* [PATCH] tools/lib/api/fs/fs.c: Fix misuse of strncpy()
@ 2018-07-21 2:10 Ben Hutchings
0 siblings, 0 replies; only message in thread
From: Ben Hutchings @ 2018-07-21 2:10 UTC (permalink / raw)
To: Jiri Olsa, Arnaldo Carvalho de Melo; +Cc: linux-kernel
[-- Attachment #1: Type: text/plain, Size: 1132 bytes --]
gcc 8 reports:
In function 'fs__env_override',
inlined from 'fs__get_mountpoint' at fs/fs.c:228:6:
fs/fs.c:222:2: error: 'strncpy' specified bound 4096 equals destination size [-Werror=stringop-truncation]
strncpy(fs->path, override_path, sizeof(fs->path));
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
I'm not convinced it makes sense to truncate the copied string here,
but since we're already doing so let's ensure it's still null-
terminated. Use strlcpy() instead.
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
Cc: stable@vger.kernel.org
---
tools/lib/api/fs/fs.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
--- a/tools/lib/api/fs/fs.c
+++ b/tools/lib/api/fs/fs.c
@@ -12,6 +12,7 @@
#include <fcntl.h>
#include <unistd.h>
#include <sys/mount.h>
+#include <linux/string.h>
#include "fs.h"
#include "debug-internal.h"
@@ -219,7 +220,7 @@ static bool fs__env_override(struct fs *
return false;
fs->found = true;
- strncpy(fs->path, override_path, sizeof(fs->path));
+ strlcpy(fs->path, override_path, sizeof(fs->path));
return true;
}
[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 811 bytes --]
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2018-07-21 2:10 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-07-21 2:10 [PATCH] tools/lib/api/fs/fs.c: Fix misuse of strncpy() Ben Hutchings
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).