From e77f354ca39576be2ae14d373e20dadb1d53f646 Mon Sep 17 00:00:00 2001 From: William Casarin Date: Thu, 15 Oct 2020 08:48:07 -0700 Subject: [PATCH] serve: fix gcc-9.3.0 error in serve_autoindex MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit gcc 9.3.0 catches an off-by-one error with strncat in serve_autoindex where it might not write a 0 byte: In function ‘strncat’, inlined from ‘serve_autoindex’ at src/serve.c:60:3: /nix/store/...glibc-2.31-dev/include/bits/string_fortified.h:136:10: error: ‘__builtin___strncat_chk’ specified bound 4097 equals destination size [-Werror=stringop-overflow=] Signed-off-by: William Casarin --- src/serve.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/serve.c b/src/serve.c index e42944e..bcb4b8c 100644 --- a/src/serve.c +++ b/src/serve.c @@ -57,7 +57,7 @@ serve_autoindex(struct gmnisrv_client *client, const char *path) while ((ent = readdir(dirp)) != NULL) { char fpath[PATH_MAX + 1]; strcpy(fpath, path); - strncat(fpath, ent->d_name, sizeof(fpath)); + strncat(fpath, ent->d_name, sizeof(fpath)-1); struct stat st; if (stat(fpath, &st) != 0) {