perf dso: Fix unchecked usage of strncpy()
tip-bot for Arnaldo Carvalho de Melo
merge botCommit-ID: 9e107dbd15d087a4879184b5cf3deacdc2faf903 Gitweb: https://git.kernel.org/tip/9e107dbd15d087a4879184b5cf3deacdc2faf903 Author: Arnaldo Carvalho de Melo <[email protected]> AuthorDate: Thu, 6 Dec 2018 10:49:46 -0300 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Thu, 6 Dec 2018 14:12:35 -0300
perf dso: Fix unchecked usage of strncpy()
The strncpy() function may leave the destination string buffer unterminated, better use strlcpy() that we have a __weak fallback implementation for systems without it.
This fixes this warning on an Alpine Linux Edge system with gcc 8.2:
In function 'decompress_kmodule',
inlined from 'dso__decompress_kmodule_fd' at util/dso.c:305:9:
util/dso.c:298:3: error: 'strncpy' destination unchanged after copying no bytes [-Werror=stringop-truncation]
strncpy(pathname, tmpbuf, len);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
CC /tmp/build/perf/util/values.o
CC /tmp/build/perf/util/debug.occ1: all warnings being treated as errors
Cc Adrian Hunter <[email protected]>
Cc Jiri Olsa <[email protected]>
Cc Namhyung Kim <[email protected]>
Fixes c9a8a6131fb6 ("perf tools: Move the temp file processing into decompress_kmodule")
Signed-off-by Arnaldo Carvalho de Melo <[email protected]>
--- tools/perf/util/dso.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/util/dso.c +1 -1
@@ -295,7 +295,7 @@ static int decompress_kmodule(struct dso *dso, const char *name,unlink (tmpbuf);if (pathname && (fd >=0 )) -strncpy (pathname, tmpbuf, len); +strlcpy (pathname, tmpbuf, len);return fd; }