Skip to content

Commit ce93c0b

Browse files
Ilya ShchipletsovKernel Patches Daemon
Ilya Shchipletsov
authored and
Kernel Patches Daemon
committed
selftests/bpf: Add test cases for various pointer specifiers
Extend snprintf negative tests to cover pointer specifiers to prevent possible invalid handling of %p% from happening again. ./test_progs -t snprintf #302/1 snprintf/snprintf_positive:OK #302/2 snprintf/snprintf_negative:OK #302 snprintf:OK #303 snprintf_btf:OK Summary: 2/2 PASSED, 0 SKIPPED, 0 FAILED Co-developed-by: Nikita Marushkin <[email protected]> Signed-off-by: Nikita Marushkin <[email protected]> Signed-off-by: Ilya Shchipletsov <[email protected]> Acked-by: Yonghong Song <[email protected]> Acked-by: Florent Revest <[email protected]>
1 parent 684b1bb commit ce93c0b

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

tools/testing/selftests/bpf/prog_tests/snprintf.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,21 @@ static void test_snprintf_negative(void)
116116
ASSERT_ERR(load_single_snprintf("%llc"), "invalid specifier 7");
117117
ASSERT_ERR(load_single_snprintf("\x80"), "non ascii character");
118118
ASSERT_ERR(load_single_snprintf("\x1"), "non printable character");
119+
120+
ASSERT_OK(load_single_snprintf("valid %p"), "valid usage");
121+
122+
ASSERT_ERR(load_single_snprintf("%p%"), "too many specifiers 1");
123+
ASSERT_ERR(load_single_snprintf("%pK%"), "too many specifiers 2");
124+
ASSERT_ERR(load_single_snprintf("%px%"), "too many specifiers 3");
125+
ASSERT_ERR(load_single_snprintf("%ps%"), "too many specifiers 4");
126+
ASSERT_ERR(load_single_snprintf("%pS%"), "too many specifiers 5");
127+
ASSERT_ERR(load_single_snprintf("%pB%"), "too many specifiers 6");
128+
ASSERT_ERR(load_single_snprintf("%pi4%"), "too many specifiers 7");
129+
ASSERT_ERR(load_single_snprintf("%pI4%"), "too many specifiers 8");
130+
ASSERT_ERR(load_single_snprintf("%pi6%"), "too many specifiers 9");
131+
ASSERT_ERR(load_single_snprintf("%pI6%"), "too many specifiers 10");
132+
ASSERT_ERR(load_single_snprintf("%pks%"), "too many specifiers 11");
133+
ASSERT_ERR(load_single_snprintf("%pus%"), "too many specifiers 12");
119134
}
120135

121136
void test_snprintf(void)

0 commit comments

Comments
 (0)