1
0
mirror of https://git.sr.ht/~sircmpwn/gmnisrv synced 2024-06-08 17:30:43 +00:00

serve: fix gcc-9.3.0 error in serve_autoindex

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 <jb55@jb55.com>
This commit is contained in:
William Casarin 2020-10-15 08:48:07 -07:00 committed by Drew DeVault
parent 9d17ce46b0
commit e77f354ca3

View File

@ -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) {