efi/printf: Handle null string input

Print "(null)" for 's' if the input is a NULL pointer.

Signed-off-by: Arvind Sankar <nivedita@alum.mit.edu>
Link: https://lore.kernel.org/r/20200518190716.751506-14-nivedita@alum.mit.edu
Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
This commit is contained in:
Arvind Sankar 2020-05-18 15:07:05 -04:00 committed by Ard Biesheuvel
parent dec6119952
commit fb031937a8
1 changed files with 5 additions and 0 deletions

View File

@ -14,6 +14,7 @@
#include <linux/compiler.h>
#include <linux/ctype.h>
#include <linux/limits.h>
#include <linux/string.h>
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))