* [PATCH v2] tiny-printf: handle NULL pointer for %s format string
@ 2025-05-19 19:25 ant.v.moryakov
0 siblings, 0 replies; only message in thread
From: ant.v.moryakov @ 2025-05-19 19:25 UTC (permalink / raw)
To: trix; +Cc: linux-kernel, Anton Moryakov
From: Anton Moryakov <ant.v.moryakov@gmail.com>
Avoid NULL pointer dereference in string formatting by printing "(null)"
when a NULL pointer is passed to a %s format specifier.
This change makes the behavior consistent with standard printf()
implementations and prevents potential crashes in constrained environments.
Signed-off-by: Anton Moryakov <ant.v.moryakov@gmail.com>
---
lib/tiny-printf.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/lib/tiny-printf.c b/lib/tiny-printf.c
index 2a7a4d286c0..df5f6829db5 100644
--- a/lib/tiny-printf.c
+++ b/lib/tiny-printf.c
@@ -307,6 +307,8 @@ static int _vprintf(struct printf_info *info, const char *fmt, va_list va)
break;
case 's':
p = va_arg(va, char*);
+ if (!p)
+ p = "(null)";
break;
case '%':
out(info, '%');
--
2.34.1
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2025-05-19 19:26 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-05-19 19:25 [PATCH v2] tiny-printf: handle NULL pointer for %s format string ant.v.moryakov
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®