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

selftests/bpf: fix a test for snprintf() overflow

The snprintf() function returns the number of bytes which *would*
have been copied if there were space. In other words, it can be
> sizeof(pin_path).

Fixes: c0fa1b6c3efc ("bpf: btf: Add BTF tests")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Acked-by: Martin KaFai Lau <kafai@fb.com>
Link: https://lore.kernel.org/r/YtZ+aD/tZMkgOUw+@kili
Signed-off-by: Alexei Starovoitov <ast@kernel.org>

authored by

Dan Carpenter and committed by
Alexei Starovoitov
c5d22f4c 979855d3

+1 -1
+1 -1
tools/testing/selftests/bpf/prog_tests/btf.c
··· 5338 5338 ret = snprintf(pin_path, sizeof(pin_path), "%s/%s", 5339 5339 "/sys/fs/bpf", test->map_name); 5340 5340 5341 - if (CHECK(ret == sizeof(pin_path), "pin_path %s/%s is too long", 5341 + if (CHECK(ret >= sizeof(pin_path), "pin_path %s/%s is too long", 5342 5342 "/sys/fs/bpf", test->map_name)) { 5343 5343 err = -1; 5344 5344 goto done;