From fb031937a86874e6d663542bdbd83e310c13610e Mon Sep 17 00:00:00 2001 From: Arvind Sankar Date: Mon, 18 May 2020 15:07:05 -0400 Subject: [PATCH] efi/printf: Handle null string input Print "(null)" for 's' if the input is a NULL pointer. Signed-off-by: Arvind Sankar Link: https://lore.kernel.org/r/20200518190716.751506-14-nivedita@alum.mit.edu Signed-off-by: Ard Biesheuvel --- drivers/firmware/efi/libstub/vsprintf.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/drivers/firmware/efi/libstub/vsprintf.c b/drivers/firmware/efi/libstub/vsprintf.c index 27685c7..d427a7b 100644 --- a/drivers/firmware/efi/libstub/vsprintf.c +++ b/drivers/firmware/efi/libstub/vsprintf.c @@ -14,6 +14,7 @@ #include #include +#include #include static int skip_atoi(const char **s) @@ -356,7 +357,11 @@ int vsprintf(char *buf, const char *fmt, va_list ap) continue; case 's': + if (precision < 0) + precision = INT_MAX; s = va_arg(args, char *); + if (!s) + s = precision < 6 ? "" : "(null)"; len = strnlen(s, precision); if (!(flags & LEFT)) -- 2.7.4