1 From 5192bde7d98c99f2cd80225649e3c2e7493722f7 Mon Sep 17 00:00:00 2001
2 From: Arnaldo Carvalho de Melo <acme@redhat.com>
3 Date: Thu, 6 Dec 2018 11:09:46 -0300
4 Subject: perf header: Fix unchecked usage of strncpy()
6 From: Arnaldo Carvalho de Melo <acme@redhat.com>
8 commit 5192bde7d98c99f2cd80225649e3c2e7493722f7 upstream.
10 The strncpy() function may leave the destination string buffer
11 unterminated, better use strlcpy() that we have a __weak fallback
12 implementation for systems without it.
14 This fixes this warning on an Alpine Linux Edge system with gcc 8.2:
16 util/header.c: In function 'perf_event__synthesize_event_update_name':
17 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]
18 strncpy(ev->data, evsel->name, len);
19 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
20 util/header.c:3618:15: note: length computed here
21 size_t len = strlen(evsel->name);
24 Cc: Adrian Hunter <adrian.hunter@intel.com>
25 Cc: Jiri Olsa <jolsa@kernel.org>
26 Cc: Namhyung Kim <namhyung@kernel.org>
27 Fixes: a6e5281780d1 ("perf tools: Add event_update event unit type")
28 Link: https://lkml.kernel.org/n/tip-wycz66iy8dl2z3yifgqf894p@git.kernel.org
29 Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
30 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
33 tools/perf/util/header.c | 2 +-
34 1 file changed, 1 insertion(+), 1 deletion(-)
36 --- a/tools/perf/util/header.c
37 +++ b/tools/perf/util/header.c
38 @@ -3027,7 +3027,7 @@ perf_event__synthesize_event_update_name
42 - strncpy(ev->data, evsel->name, len);
43 + strlcpy(ev->data, evsel->name, len + 1);
44 err = process(tool, (union perf_event*) ev, NULL, NULL);