From 58eeb2289ab9bd8acad41a589431bbdbf7622595 Mon Sep 17 00:00:00 2001 From: KP Singh Date: Wed, 23 Oct 2019 17:40:38 +0200 Subject: libbpf: Fix strncat bounds error in libbpf_prog_type_by_name MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit On compiling samples with this change, one gets an error: error: ‘strncat’ specified bound 118 equals destination size [-Werror=stringop-truncation] strncat(dst, name + section_names[i].len, ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ sizeof(raw_tp_btf_name) - (dst - raw_tp_btf_name)); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ strncat requires the destination to have enough space for the terminating null byte. Fixes: f75a697e09137 ("libbpf: Auto-detect btf_id of BTF-based raw_tracepoint") Signed-off-by: KP Singh Signed-off-by: Alexei Starovoitov Link: https://lore.kernel.org/bpf/20191023154038.24075-1-kpsingh@chromium.org --- tools/lib/bpf/libbpf.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tools') diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c index 8b4d765c422b..d71631a01926 100644 --- a/tools/lib/bpf/libbpf.c +++ b/tools/lib/bpf/libbpf.c @@ -4690,7 +4690,7 @@ int libbpf_prog_type_by_name(const char *name, enum bpf_prog_type *prog_type, } /* prepend "btf_trace_" prefix per kernel convention */ strncat(dst, name + section_names[i].len, - sizeof(raw_tp_btf_name) - (dst - raw_tp_btf_name)); + sizeof(raw_tp_btf_name) - sizeof("btf_trace_")); ret = btf__find_by_name(btf, raw_tp_btf_name); btf__free(btf); if (ret <= 0) { -- cgit v1.2.3