summaryrefslogtreecommitdiff
path: root/lib/tiny-printf.c
diff options
context:
space:
mode:
authorBenedikt Spranger <b.spranger@linutronix.de>2024-10-18 10:30:02 +0200
committerEugen Hristev <eugen.hristev@linaro.org>2024-11-29 12:59:27 +0200
commitf0dab28915b7890d5a7d958bc4b6f9b61f535cb4 (patch)
treecab3a018ce691e141ef410c1ca825e08e5d204af /lib/tiny-printf.c
parent62224280d9e89648ae90346c0aede76f9b7e7610 (diff)
tiny-printf: Handle NULL pointer argument to %s
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>
Diffstat (limited to 'lib/tiny-printf.c')
-rw-r--r--lib/tiny-printf.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/lib/tiny-printf.c b/lib/tiny-printf.c
index cc1dfe61cf7..0503c17341f 100644
--- a/lib/tiny-printf.c
+++ b/lib/tiny-printf.c
@@ -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' : ' ');