Commit 118708ed authored by Rusty Russell's avatar Rusty Russell

tal/path: handle weird case of path_join("")

It seems most sensible to make it a noop, but it definitely shouldn't
access out of bounds as it does.

Reported-by: Russ Dill
Fixes: #61
Signed-off-by: default avatarRusty Russell <rusty@rustcorp.com.au>
parent 6ac981db
......@@ -52,7 +52,7 @@ char *path_join(const tal_t *ctx, const char *base, const char *a)
ret = tal_dup_arr(ctx, char, base, len, 1 + strlen(a) + 1);
if (!ret)
goto out;
if (ret[len-1] != PATH_SEP)
if (len != 0 && ret[len-1] != PATH_SEP)
ret[len++] = PATH_SEP;
strcpy(ret + len, a);
......
......@@ -6,7 +6,7 @@ int main(void)
{
char *path, *ctx = tal_strdup(NULL, "ctx");
plan_tests(34);
plan_tests(36);
path = path_join(ctx, "foo", "bar");
ok1(streq(path, "foo/bar"));
......@@ -85,6 +85,11 @@ int main(void)
ok1(!path);
ok1(!tal_first(ctx));
path = path_join(ctx, "", "bar");
ok1(streq(path, "bar"));
ok1(tal_parent(path) == ctx);
tal_free(path);
tal_free(ctx);
return exit_status();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment