[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20241028195343.2104-3-rabbelkin@mail.ru>
Date: Mon, 28 Oct 2024 19:53:41 +0000
From: Ilya Shchipletsov <rabbelkin@...l.ru>
To: bpf@...r.kernel.org
Cc: Ilya Shchipletsov <rabbelkin@...l.ru>,
Alexei Starovoitov <ast@...nel.org>,
Daniel Borkmann <daniel@...earbox.net>,
Andrii Nakryiko <andrii@...nel.org>,
Martin KaFai Lau <martin.lau@...ux.dev>,
Eduard Zingerman <eddyz87@...il.com>,
Song Liu <song@...nel.org>,
Yonghong Song <yonghong.song@...ux.dev>,
John Fastabend <john.fastabend@...il.com>,
KP Singh <kpsingh@...nel.org>,
Stanislav Fomichev <sdf@...ichev.me>,
Hao Luo <haoluo@...gle.com>,
Jiri Olsa <jolsa@...nel.org>,
Florent Revest <revest@...omium.org>,
Nikita Marushkin <hfggklm@...il.com>,
lvc-project@...uxtesting.org,
linux-kernel@...r.kernel.org
Subject: [PATCH bpf v2 2/2] 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 <hfggklm@...il.com>
Signed-off-by: Nikita Marushkin <hfggklm@...il.com>
Signed-off-by: Ilya Shchipletsov <rabbelkin@...l.ru>
---
tools/testing/selftests/bpf/prog_tests/snprintf.c | 15 +++++++++++++++
1 file changed, 15 insertions(+)
diff --git a/tools/testing/selftests/bpf/prog_tests/snprintf.c b/tools/testing/selftests/bpf/prog_tests/snprintf.c
index 4be6fdb78c6a..b5b6371e09bb 100644
--- a/tools/testing/selftests/bpf/prog_tests/snprintf.c
+++ b/tools/testing/selftests/bpf/prog_tests/snprintf.c
@@ -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)
--
2.43.0
Powered by blists - more mailing lists