ctfw.c: Avoid trailing forward slash

Otherwise, this would generate strings such as "directory//resource" if
dirpath contained a trailing slash, which could be problematic for users
relying on ctfw.
This commit is contained in:
Xavier Del Campo Romero 2023-06-06 03:36:45 +02:00
parent 6adf1c44ad
commit 6e9ce3a25b
Signed by: xavi
GPG Key ID: 84FF3612A9BF43F2
1 changed files with 2 additions and 1 deletions

3
cftw.c
View File

@ -29,12 +29,13 @@ int cftw(const char *const dirpath, int (*const fn)(const char *,
if (!strcmp(path, ".") || !strcmp(path, ".."))
continue;
const char *const sep = dirpath[strlen(dirpath) - 1] == '/' ? "" : "/";
struct stat sb;
struct dynstr d;
dynstr_init(&d);
if (dynstr_append(&d, "%s/%s", dirpath, path))
if (dynstr_append(&d, "%s%s%s", dirpath, sep, path))
{
fprintf(stderr, "%s: dynstr_append failed\n", __func__);
return -1;