selftests/bpf: Add negative test cases for snprintf
authorPaul Chaignon <paul.chaignon@gmail.com>
Tue, 1 Jul 2025 19:48:03 +0000 (21:48 +0200)
committerAlexei Starovoitov <ast@kernel.org>
Tue, 1 Jul 2025 22:22:46 +0000 (15:22 -0700)
This patch adds a couple negative test cases with a trailing % at the
end of the format string. The %p% case was fixed by the previous commit,
whereas the %s% case was already successfully rejected before.

Acked-by: Yonghong Song <yonghong.song@linux.dev>
Signed-off-by: Paul Chaignon <paul.chaignon@gmail.com>
Link: https://lore.kernel.org/r/0669bf6eb4f9e5bb10e949d60311c06e2d942447.1751395489.git.paul.chaignon@gmail.com
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
tools/testing/selftests/bpf/prog_tests/snprintf.c

index 4be6fdb78c6a12cfd1af54cfcec52e91956f7b95..594441acb7071fe13891100c4f425a31f253915e 100644 (file)
@@ -116,6 +116,8 @@ static void test_snprintf_negative(void)
        ASSERT_ERR(load_single_snprintf("%llc"), "invalid specifier 7");
        ASSERT_ERR(load_single_snprintf("\x80"), "non ascii character");
        ASSERT_ERR(load_single_snprintf("\x1"), "non printable character");
+       ASSERT_ERR(load_single_snprintf("%p%"), "invalid specifier 8");
+       ASSERT_ERR(load_single_snprintf("%s%"), "invalid specifier 9");
 }
 
 void test_snprintf(void)