]> www.infradead.org Git - users/dwmw2/linux.git/commitdiff
selftests/bpf: fix a test for snprintf() overflow
authorDan Carpenter <dan.carpenter@oracle.com>
Tue, 19 Jul 2022 09:50:32 +0000 (12:50 +0300)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sun, 21 Aug 2022 13:15:47 +0000 (15:15 +0200)
[ Upstream commit c5d22f4cfe8dfb93f1db0a1e7e2e7ebc41395d98 ]

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>
Signed-off-by: Sasha Levin <sashal@kernel.org>
tools/testing/selftests/bpf/prog_tests/btf.c

index 93162484c2cad07dac117755c8e54e4f25e6eb2a..48b01150e703fec4314998296a5b911e27203e9d 100644 (file)
@@ -4758,7 +4758,7 @@ static void do_test_pprint(int test_num)
        ret = snprintf(pin_path, sizeof(pin_path), "%s/%s",
                       "/sys/fs/bpf", test->map_name);
 
-       if (CHECK(ret == sizeof(pin_path), "pin_path %s/%s is too long",
+       if (CHECK(ret >= sizeof(pin_path), "pin_path %s/%s is too long",
                  "/sys/fs/bpf", test->map_name)) {
                err = -1;
                goto done;