diff options
author | Eric Biggers <ebiggers@google.com> | 2023-01-21 12:32:22 -0800 |
---|---|---|
committer | Theodore Ts'o <tytso@mit.edu> | 2023-01-27 12:38:31 -0500 |
commit | 44ee1fb80bd347ba92c38a4e60060229f671dcd8 (patch) | |
tree | fae4f4226f6b4f2d9d0e80ec1ad2f54977f60619 /misc | |
parent | 58830e58551aef70e19c992f880e378125e5d9d9 (diff) | |
download | e2fsprogs-44ee1fb80bd347ba92c38a4e60060229f671dcd8.tar.gz |
misc/fuse2fs: avoid error-prone strncpy() pattern
'strncpy(dst, src, strlen(src))' is usually wrong, as it doesn't copy
the null terminator. For this reason, it causes a -Wstringop-truncation
warning with gcc 8 and later.
The code happens to be correct anyway, since the destination buffer is
zero-initialized. But to avoid relying on this, let's just copy the
terminating null.
Signed-off-by: Eric Biggers <ebiggers@google.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
Diffstat (limited to 'misc')
-rw-r--r-- | misc/fuse2fs.c | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/misc/fuse2fs.c b/misc/fuse2fs.c index c5957212..6d4bcf4f 100644 --- a/misc/fuse2fs.c +++ b/misc/fuse2fs.c @@ -2508,9 +2508,10 @@ static int copy_names(char *name, char *value EXT2FS_ATTR((unused)), size_t value_len EXT2FS_ATTR((unused)), void *data) { char **b = data; + size_t name_len = strlen(name); - strncpy(*b, name, strlen(name)); - *b = *b + strlen(name) + 1; + memcpy(*b, name, name_len + 1); + *b = *b + name_len + 1; return 0; } |