Skip to content

Commit 16977a9

Browse files
acmelgregkh
authored andcommitted
perf header: Fix unchecked usage of strncpy()
commit 5192bde upstream. 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: util/header.c: In function 'perf_event__synthesize_event_update_name': util/header.c:3625:2: error: 'strncpy' output truncated before terminating nul copying as many bytes from a string as its length [-Werror=stringop-truncation] strncpy(ev->data, evsel->name, len); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ util/header.c:3618:15: note: length computed here size_t len = strlen(evsel->name); ^~~~~~~~~~~~~~~~~~~ Cc: Adrian Hunter <[email protected]> Cc: Jiri Olsa <[email protected]> Cc: Namhyung Kim <[email protected]> Fixes: a6e5281 ("perf tools: Add event_update event unit type") Link: https://lkml.kernel.org/n/[email protected] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 07d6f72 commit 16977a9

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

tools/perf/util/header.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3027,7 +3027,7 @@ perf_event__synthesize_event_update_name(struct perf_tool *tool,
30273027
if (ev == NULL)
30283028
return -ENOMEM;
30293029

3030-
strncpy(ev->data, evsel->name, len);
3030+
strlcpy(ev->data, evsel->name, len + 1);
30313031
err = process(tool, (union perf_event*) ev, NULL, NULL);
30323032
free(ev);
30333033
return err;

0 commit comments

Comments
 (0)