Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

tools, bpftool: Avoid array index warnings.

The bpf_caps array is shorter without CAP_BPF, avoid out of bounds reads
if this isn't defined. Working around this avoids -Wno-array-bounds with
clang.

Signed-off-by: Ian Rogers <irogers@google.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Reviewed-by: Tobias Klauser <tklauser@distanz.ch>
Acked-by: Andrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/bpf/20201027233646.3434896-1-irogers@google.com

authored by

Ian Rogers and committed by
Daniel Borkmann
1e6f5dcc e5e1a4bc

+6 -1
+6 -1
tools/bpf/bpftool/feature.c
··· 843 843 else 844 844 p_err("missing %s%s%s%s%s%s%s%srequired for full feature probing; run as root or use 'unprivileged'", 845 845 capability_msg(bpf_caps, 0), 846 + #ifdef CAP_BPF 846 847 capability_msg(bpf_caps, 1), 847 848 capability_msg(bpf_caps, 2), 848 - capability_msg(bpf_caps, 3)); 849 + capability_msg(bpf_caps, 3) 850 + #else 851 + "", "", "", "", "", "" 852 + #endif /* CAP_BPF */ 853 + ); 849 854 goto exit_free; 850 855 } 851 856