tiny-printf: Handle NULL pointer argument to %s
authorBenedikt Spranger <b.spranger@linutronix.de>
Fri, 18 Oct 2024 08:30:02 +0000 (10:30 +0200)
committerEugen Hristev <eugen.hristev@linaro.org>
Fri, 29 Nov 2024 10:59:27 +0000 (12:59 +0200)
A NULL pointer argument to %s causes a NULL pointer dereference in the
fixed width numerical printout code, since p is overwritten with NULL.
In case of %s width is 0. Check width before dereferencing the pointer.

Signed-off-by: Benedikt Spranger <b.spranger@linutronix.de>
Reviewed-by: John Ogness <john.ogness@linutronix.de>
lib/tiny-printf.c

index cc1dfe6..0503c17 100644 (file)
@@ -312,7 +312,7 @@ static int _vprintf(struct printf_info *info, const char *fmt, va_list va)
 
                        *info->bf = 0;
                        info->bf = p;
-                       while (*info->bf++ && width > 0)
+                       while (width > 0 && info->bf && *info->bf++)
                                width--;
                        while (width-- > 0)
                                info->putc(info, lz ? '0' : ' ');