[PATCH] printf: add bad-pointer tests for %ptT and %ptS

From: Shuvam Pandey

Date: Mon Mar 16 2026 - 06:59:05 EST


The printf KUnit suite exercises valid %ptR, %ptT, and %ptS inputs,
but it does not cover bad pointers for the time64_t and timespec64
paths.

Add NULL and low-address pointer cases for %ptT and %ptS. The new
checks verify that time_and_date() rejects bad pointers before
dereferencing them and formats them as "(null)" or "(efault)".

Validated with the printf KUnit suite on arm64 QEMU and an
incremental W=1 build of lib/tests/printf_kunit.o.

Signed-off-by: Shuvam Pandey <shuvampandey1@xxxxxxxxx>
---
lib/tests/printf_kunit.c | 7 +++++++
1 file changed, 7 insertions(+)

diff --git a/lib/tests/printf_kunit.c b/lib/tests/printf_kunit.c
index f6f21b445ece..c64bfe79652e 100644
--- a/lib/tests/printf_kunit.c
+++ b/lib/tests/printf_kunit.c
@@ -509,6 +509,13 @@ time_and_date(struct kunit *kunittest)
struct timespec64 ts = { .tv_sec = t, .tv_nsec = 11235813 };

test("(%pt?)", "%pt", &tm);
+
+ /* %ptT and %ptS reject bad pointers before dereference. */
+ test("(null)", "%ptT", NULL);
+ test("(efault)", "%ptT", PTR_INVALID);
+ test("(null)", "%ptS", NULL);
+ test("(efault)", "%ptS", PTR_INVALID);
+
test("2018-11-26T05:35:43", "%ptR", &tm);
test("0118-10-26T05:35:43", "%ptRr", &tm);
test("05:35:43|2018-11-26", "%ptRt|%ptRd", &tm, &tm);
--
2.50.1 (Apple Git-155)