Skip to content

Commit

Permalink
Fix CLN service startup failure by trimming spaces in config parameters
Browse files Browse the repository at this point in the history
Signed-off-by: Max Rantil <rantil@pm.me>
  • Loading branch information
maxrantil committed May 16, 2024
1 parent 2d0778e commit 73363f8
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 5 deletions.
30 changes: 30 additions & 0 deletions ccan/ccan/tal/str/str.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,36 @@ char *tal_strndup_(const tal_t *ctx, const char *p, size_t n, const char *label)
return ret;
}

char *tal_strtrim(const tal_t *ctx, const char *str) {
const char *start;
const char *end;
size_t len;

/* Handle NULL or empty string input */
if (!str) {
return tal_strdup(ctx, "");
}

start = str;
while (*start && isspace((unsigned char)*start)) {
start++;
}

/* If the string is all spaces, return an empty string */
if (*start == '\0') {
return tal_strdup(ctx, "");
}

end = str + strlen(str) - 1;
while (end > start && isspace((unsigned char)*end)) {
end--;
}

len = end - start + 1;

return tal_strndup(ctx, start, len);
}

char *tal_fmt_(const tal_t *ctx, const char *label, const char *fmt, ...)
{
va_list ap;
Expand Down
10 changes: 10 additions & 0 deletions ccan/ccan/tal/str/str.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,16 @@ char *tal_strdup_(const tal_t *ctx, const char *p TAKES, const char *label);
char *tal_strndup_(const tal_t *ctx, const char *p TAKES, size_t n,
const char *label);

/**
* tal_strtrim - Create a trimmed version of the string using tal.
* @ctx: NULL, or tal allocated object to be parent.
* @str: the string to trim.
*
* Returns a new string that has leading and trailing spaces removed,
* allocated using tal.
*/
char *tal_strtrim(const tal_t *ctx, const char *str);

/**
* tal_fmt - allocate a formatted string
* @ctx: NULL, or tal allocated object to be parent.
Expand Down
13 changes: 9 additions & 4 deletions common/configdir.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,16 @@ static struct configvar **gather_file_configvars(const tal_t *ctx,
/* Break into lines. */
lines = tal_strsplit(contents, contents, "\r\n", STR_EMPTY_OK);
for (size_t i = 0; i < tal_count(lines) - 1; i++) {
char *trimmed_line = tal_strtrim(tmpctx, lines[i]);

/* Comments & blank lines*/
if (strstarts(lines[i], "#") || streq(lines[i], ""))
if (strstarts(trimmed_line[i], "#") || streq(trimmed_line[i], "")) {
tal_free(trimmed_line);
continue;
}

if (strstarts(lines[i], "include ")) {
const char *included = lines[i] + strlen("include ");
if (strstarts(trimmed_line[i], "include ")) {
const char *included = trimmed_line[i] + strlen("include ");
struct configvar **sub;

if (include_depth > 100)
Expand All @@ -99,7 +103,8 @@ static struct configvar **gather_file_configvars(const tal_t *ctx,
}

tal_arr_expand(&cvs,
configvar_new(cvs, src, filename, i+1, lines[i]));
configvar_new(cvs, src, filename, i+1, trimmed_line[i]));
tal_free(trimmed_line);
}
return cvs;
}
Expand Down
2 changes: 1 addition & 1 deletion contrib/startup_regtest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ start_nodes() {
funder-min-their-funding=10000
funder-per-channel-max=100000
funder-fuzz-percent=0
funder-lease-requests-only=false
funder-lease-requests-only=false
lease-fee-base-sat=2sat
lease-fee-basis=50
invoices-onchain-fallback
Expand Down

0 comments on commit 73363f8

Please sign in to comment.