aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorThomas Weißschuh <thomas.weissschuh@linutronix.de>2025-04-11 11:00:54 +0200
committerThomas Weißschuh <linux@weissschuh.net>2025-04-22 10:59:06 +0200
commitb0bd7760df94714f78ccf98b3aa612ed71e48770 (patch)
treec52caf82698283c73a2577b413fd9abc0dd9505d
parentselftests/nolibc: rename vfprintf test suite (diff)
downloadwireguard-linux-b0bd7760df94714f78ccf98b3aa612ed71e48770.tar.xz
wireguard-linux-b0bd7760df94714f78ccf98b3aa612ed71e48770.zip
selftests/nolibc: add test for snprintf() truncation
Now that we have a proper snprintf() implementation, make sure truncation is handled properly. Signed-off-by: Thomas Weißschuh <thomas.weissschuh@linutronix.de> Acked-by: Willy Tarreau <w@1wt.eu>
-rw-r--r--tools/testing/selftests/nolibc/nolibc-test.c4
1 files changed, 3 insertions, 1 deletions
diff --git a/tools/testing/selftests/nolibc/nolibc-test.c b/tools/testing/selftests/nolibc/nolibc-test.c
index 5fb4319545d5..33cd64a1b768 100644
--- a/tools/testing/selftests/nolibc/nolibc-test.c
+++ b/tools/testing/selftests/nolibc/nolibc-test.c
@@ -1306,7 +1306,8 @@ static int expect_vfprintf(int llen, int c, const char *expected, const char *fm
va_start(args, fmt);
- w = vsnprintf(buf, sizeof(buf), fmt, args);
+ /* Only allow writing 21 bytes, to test truncation */
+ w = vsnprintf(buf, 21, fmt, args);
va_end(args);
if (w != c) {
@@ -1412,6 +1413,7 @@ static int run_printf(int min, int max)
CASE_TEST(pointer); EXPECT_VFPRINTF(3, "0x1", "%p", (void *) 0x1); break;
CASE_TEST(uintmax_t); EXPECT_VFPRINTF(20, "18446744073709551615", "%ju", 0xffffffffffffffffULL); break;
CASE_TEST(intmax_t); EXPECT_VFPRINTF(20, "-9223372036854775807", "%jd", 0x8000000000000001LL); break;
+ CASE_TEST(truncation); EXPECT_VFPRINTF(25, "01234567890123456789", "%s", "0123456789012345678901234"); break;
CASE_TEST(scanf); EXPECT_ZR(1, test_scanf()); break;
case __LINE__:
return ret; /* must be last */