Commit 0d0fa1a6 authored by Arnaldo Carvalho de Melo's avatar Arnaldo Carvalho de Melo Committed by Greg Kroah-Hartman

perf dso: Fix unchecked usage of strncpy()

[ Upstream commit fca5085c ]

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.o
  cc1: all warnings being treated as errors

Cc: Adrian Hunter <>
Cc: Jiri Olsa <>
Cc: Namhyung Kim <>
Fixes: c9a8a613 ("perf tools: Move the temp file processing into decompress_kmodule")
Link: 's avatarArnaldo Carvalho de Melo <>
Signed-off-by: 's avatarSasha Levin <>
parent 411966cc
......@@ -295,7 +295,7 @@ static int decompress_kmodule(struct dso *dso, const char *name,
if (pathname && (fd >= 0))
strncpy(pathname, tmpbuf, len);
strlcpy(pathname, tmpbuf, len);
return fd;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment