aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorStefan Hajnoczi <stefanha@gmail.com>2019-08-29 20:28:29 +0100
committerNikolaus Rath <Nikolaus@rath.org>2019-08-29 20:28:29 +0100
commitf39c71dcf99292c188bb6f0a117d7e118f92bfb1 (patch)
treebb41bf027212445f267b3d7a1b0dce9d601b03d8 /lib
parentab26ad4dfab74937daf99e0b7e75e4a0e148b0a7 (diff)
downloadlibfuse-f39c71dcf99292c188bb6f0a117d7e118f92bfb1.tar.gz
Avoid gcc 9.1 strncpy(3) warnings (#447)
Recent GCC releases have warnings related to common strncpy(3) bugs. These warnings can be avoided by explicitly NUL-terminating the buffer or using memcpy(3) when the intention is to copy just the characters without the NUL terminator. This commit fixes the following warnings: [1/27] Compiling C object 'test/9f86d08@@test_syscalls@exe/test_syscalls.c.o'. In function ‘test_socket’, inlined from ‘main’ at ../test/test_syscalls.c:1899:9: ../test/test_syscalls.c:1760:2: warning: ‘strncpy’ output may be truncated copying 108 bytes from a string of length 1023 [-Wstringop-truncation] 1760 | strncpy(su.sun_path, testsock, sizeof(su.sun_path)); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [2/27] Compiling C object 'lib/76b5a35@@fuse3@sha/fuse.c.o'. ../lib/fuse.c: In function ‘add_name’: ../lib/fuse.c:968:2: warning: ‘strncpy’ output truncated before terminating nul copying as many bytes from a string as its length [-Wstringop-truncation] 968 | strncpy(s, name, len); | ^~~~~~~~~~~~~~~~~~~~~ ../lib/fuse.c:944:15: note: length computed here 944 | size_t len = strlen(name); | ^~~~~~~~~~~~ [3/27] Compiling C object 'lib/76b5a35@@fuse3@sha/fuse_lowlevel.c.o'. ../lib/fuse_lowlevel.c: In function ‘fuse_add_direntry’: ../lib/fuse_lowlevel.c:288:2: warning: ‘strncpy’ output truncated before terminating nul copying as many bytes from a string as its length [-Wstringop-truncation] 288 | strncpy(dirent->name, name, namelen); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ../lib/fuse_lowlevel.c:276:12: note: length computed here 276 | namelen = strlen(name); | ^~~~~~~~~~~~ ../lib/fuse_lowlevel.c: In function ‘fuse_add_direntry_plus’: ../lib/fuse_lowlevel.c:381:2: warning: ‘strncpy’ output truncated before terminating nul copying as many bytes from a string as its length [-Wstringop-truncation] 381 | strncpy(dirent->name, name, namelen); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ../lib/fuse_lowlevel.c:366:12: note: length computed here 366 | namelen = strlen(name); | ^~~~~~~~~~~~ Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
Diffstat (limited to 'lib')
-rwxr-xr-xlib/fuse.c2
-rw-r--r--lib/fuse_lowlevel.c4
2 files changed, 3 insertions, 3 deletions
diff --git a/lib/fuse.c b/lib/fuse.c
index ec6cc59..317abac 100755
--- a/lib/fuse.c
+++ b/lib/fuse.c
@@ -965,7 +965,7 @@ static char *add_name(char **buf, unsigned *bufsize, char *s, const char *name)
*bufsize = newbufsize;
}
s -= len;
- strncpy(s, name, len);
+ memcpy(s, name, len);
s--;
*s = '/';
diff --git a/lib/fuse_lowlevel.c b/lib/fuse_lowlevel.c
index b9f128f..918893e 100644
--- a/lib/fuse_lowlevel.c
+++ b/lib/fuse_lowlevel.c
@@ -285,7 +285,7 @@ size_t fuse_add_direntry(fuse_req_t req, char *buf, size_t bufsize,
dirent->off = off;
dirent->namelen = namelen;
dirent->type = (stbuf->st_mode & S_IFMT) >> 12;
- strncpy(dirent->name, name, namelen);
+ memcpy(dirent->name, name, namelen);
memset(dirent->name + namelen, 0, entlen_padded - entlen);
return entlen_padded;
@@ -378,7 +378,7 @@ size_t fuse_add_direntry_plus(fuse_req_t req, char *buf, size_t bufsize,
dirent->off = off;
dirent->namelen = namelen;
dirent->type = (e->attr.st_mode & S_IFMT) >> 12;
- strncpy(dirent->name, name, namelen);
+ memcpy(dirent->name, name, namelen);
memset(dirent->name + namelen, 0, entlen_padded - entlen);
return entlen_padded;