mirror of
https://github.com/hardkernel/linux.git
synced 2026-06-07 03:15:31 +09:00
perf header: Fix unchecked usage of strncpy()
[ Upstream commit7572588085] 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_unit': util/header.c:3586: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->unit, size); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ util/header.c:3579:16: note: length computed here size_t size = strlen(evsel->unit); ^~~~~~~~~~~~~~~~~~~ Cc: Adrian Hunter <adrian.hunter@intel.com> Cc: Jiri Olsa <jolsa@kernel.org> Cc: Namhyung Kim <namhyung@kernel.org> Fixes:a6e5281780("perf tools: Add event_update event unit type") Link: https://lkml.kernel.org/n/tip-fiikh5nay70bv4zskw2aa858@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com> Signed-off-by: Sasha Levin <sashal@kernel.org>
This commit is contained in:
committed by
Chris
parent
5dcf9da8e9
commit
7b5ae125dc
@@ -2988,7 +2988,7 @@ perf_event__synthesize_event_update_unit(struct perf_tool *tool,
|
||||
if (ev == NULL)
|
||||
return -ENOMEM;
|
||||
|
||||
strncpy(ev->data, evsel->unit, size);
|
||||
strlcpy(ev->data, evsel->unit, size + 1);
|
||||
err = process(tool, (union perf_event *)ev, NULL, NULL);
|
||||
free(ev);
|
||||
return err;
|
||||
|
||||
Reference in New Issue
Block a user