]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob - queue-4.19/perf-probe-fix-unchecked-usage-of-strncpy.patch
autosel patches for 4.19
[thirdparty/kernel/stable-queue.git] / queue-4.19 / perf-probe-fix-unchecked-usage-of-strncpy.patch
1 From a41f932cc380e4b924e4f5566bfdfb84a1f3c7f5 Mon Sep 17 00:00:00 2001
2 From: Arnaldo Carvalho de Melo <acme@redhat.com>
3 Date: Thu, 6 Dec 2018 11:50:08 -0300
4 Subject: perf probe: Fix unchecked usage of strncpy()
5
6 [ Upstream commit bef0b8970f27da5ca223e522a174d03e2587761d ]
7
8 The strncpy() function may leave the destination string buffer
9 unterminated, better use strlcpy() that we have a __weak fallback
10 implementation for systems without it.
11
12 In this case the 'target' buffer is coming from a list of build-ids that
13 are expected to have a len of at most (SBUILD_ID_SIZE - 1) chars, so
14 probably we're safe, but since we're using strncpy() here, use strlcpy()
15 instead to provide the intended safety checking without the using the
16 problematic strncpy() function.
17
18 This fixes this warning on an Alpine Linux Edge system with gcc 8.2:
19
20 util/probe-file.c: In function 'probe_cache__open.isra.5':
21 util/probe-file.c:427:3: error: 'strncpy' specified bound 41 equals destination size [-Werror=stringop-truncation]
22 strncpy(sbuildid, target, SBUILD_ID_SIZE);
23 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
24 cc1: all warnings being treated as errors
25
26 Cc: Adrian Hunter <adrian.hunter@intel.com>
27 Cc: Jiri Olsa <jolsa@kernel.org>
28 Cc: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
29 Cc: Namhyung Kim <namhyung@kernel.org>
30 Fixes: 1f3736c9c833 ("perf probe: Show all cached probes")
31 Link: https://lkml.kernel.org/n/tip-l7n8ggc9kl38qtdlouke5yp5@git.kernel.org
32 Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
33 Signed-off-by: Sasha Levin <sashal@kernel.org>
34 ---
35 tools/perf/util/probe-file.c | 2 +-
36 1 file changed, 1 insertion(+), 1 deletion(-)
37
38 diff --git a/tools/perf/util/probe-file.c b/tools/perf/util/probe-file.c
39 index b76088fadf3d..6a6548890d5a 100644
40 --- a/tools/perf/util/probe-file.c
41 +++ b/tools/perf/util/probe-file.c
42 @@ -424,7 +424,7 @@ static int probe_cache__open(struct probe_cache *pcache, const char *target,
43
44 if (target && build_id_cache__cached(target)) {
45 /* This is a cached buildid */
46 - strncpy(sbuildid, target, SBUILD_ID_SIZE);
47 + strlcpy(sbuildid, target, SBUILD_ID_SIZE);
48 dir_name = build_id_cache__linkname(sbuildid, NULL, 0);
49 goto found;
50 }
51 --
52 2.19.1
53