From: Ben Hutchings Date: Thu, 19 Jul 2018 22:36:52 +0000 (+0100) Subject: tools/lib/api/fs/fs.c: Fix misuse of strncpy() X-Git-Tag: archive/raspbian/4.18.10-2+rpi1^2~3 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=5b8ea832b439dcaa253c0e419839aafef4499c5f;p=linux.git tools/lib/api/fs/fs.c: Fix misuse of strncpy() 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 Gbp-Pq: Topic bugfix/all Gbp-Pq: Name tools-lib-api-fs-fs.c-fix-misuse-of-strncpy.patch --- diff --git a/tools/lib/api/fs/fs.c b/tools/lib/api/fs/fs.c index 7aba8243a0e..52cad933e8a 100644 --- a/tools/lib/api/fs/fs.c +++ b/tools/lib/api/fs/fs.c @@ -12,6 +12,7 @@ #include #include #include +#include #include "fs.h" #include "debug-internal.h" @@ -219,7 +220,7 @@ static bool fs__env_override(struct fs *fs) return false; fs->found = true; - strncpy(fs->path, override_path, sizeof(fs->path)); + strlcpy(fs->path, override_path, sizeof(fs->path)); return true; }