[PATCH] lib: add NULL pointer check for %s format
ant.v.moryakov at gmail.com
ant.v.moryakov at gmail.com
Fri May 16 20:54:47 CEST 2025
From: Anton Moryakov <ant.v.moryakov at gmail.com>
Handle NULL pointer case in string formatting (%s) by printing '(null)'
instead of dereferencing NULL pointer. Makes behavior consistent with
standard printf implementations and prevents potential crashes.
Signed-off-by: Anton Moryakov <ant.v.moryakov at 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 faf55d7f327..da596d72050 100644
--- a/lib/tiny-printf.c
+++ b/lib/tiny-printf.c
@@ -306,6 +306,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.30.2
More information about the U-Boot
mailing list