Skip to content

Commit

Permalink
selftests/bpf: Add test cases for various pointer specifiers
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
Ilya Shchipletsov authored and Kernel Patches Daemon committed Dec 3, 2024
1 parent 34451fd commit 6fd460d
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions tools/testing/selftests/bpf/prog_tests/snprintf.c
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,21 @@ 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_OK(load_single_snprintf("valid %p"), "valid usage");

ASSERT_ERR(load_single_snprintf("%p%"), "too many specifiers 1");
ASSERT_ERR(load_single_snprintf("%pK%"), "too many specifiers 2");
ASSERT_ERR(load_single_snprintf("%px%"), "too many specifiers 3");
ASSERT_ERR(load_single_snprintf("%ps%"), "too many specifiers 4");
ASSERT_ERR(load_single_snprintf("%pS%"), "too many specifiers 5");
ASSERT_ERR(load_single_snprintf("%pB%"), "too many specifiers 6");
ASSERT_ERR(load_single_snprintf("%pi4%"), "too many specifiers 7");
ASSERT_ERR(load_single_snprintf("%pI4%"), "too many specifiers 8");
ASSERT_ERR(load_single_snprintf("%pi6%"), "too many specifiers 9");
ASSERT_ERR(load_single_snprintf("%pI6%"), "too many specifiers 10");
ASSERT_ERR(load_single_snprintf("%pks%"), "too many specifiers 11");
ASSERT_ERR(load_single_snprintf("%pus%"), "too many specifiers 12");
}

void test_snprintf(void)
Expand Down

0 comments on commit 6fd460d

Please sign in to comment.