From a22bec51494a50c044416d469cc33e043480e7fd Mon Sep 17 00:00:00 2001 From: io mintz Date: Tue, 13 Oct 2020 07:05:10 +0000 Subject: [PATCH] add a missing "/" to autoindex paths With the following directory structure: /srv/gmni: baz/ foo/ /srv/gmni/baz: a /srv/gmni/foo: bar/ /srv/gmni/foo/bar: b trying to access gemini://somesite/ with autoindex=on works, but accessing /foo fails because it tries to stat /srv/gmni/foobar instead of /srv/gmni/foo/bar. This commit fixes that by adding a trailing slash. --- src/serve.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/serve.c b/src/serve.c index bcb4b8c..df08d08 100644 --- a/src/serve.c +++ b/src/serve.c @@ -56,8 +56,7 @@ serve_autoindex(struct gmnisrv_client *client, const char *path) errno = 0; while ((ent = readdir(dirp)) != NULL) { char fpath[PATH_MAX + 1]; - strcpy(fpath, path); - strncat(fpath, ent->d_name, sizeof(fpath)-1); + snprintf(fpath, sizeof(fpath), "%s/%s", path, ent->d_name); struct stat st; if (stat(fpath, &st) != 0) {