Skip to content

Commit fb03193

Browse files
nivedita76ardbiesheuvel
authored andcommitted
efi/printf: Handle null string input
Print "(null)" for 's' if the input is a NULL pointer. Signed-off-by: Arvind Sankar <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Ard Biesheuvel <[email protected]>
1 parent dec6119 commit fb03193

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

drivers/firmware/efi/libstub/vsprintf.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
#include <linux/compiler.h>
1616
#include <linux/ctype.h>
17+
#include <linux/limits.h>
1718
#include <linux/string.h>
1819

1920
static int skip_atoi(const char **s)
@@ -356,7 +357,11 @@ int vsprintf(char *buf, const char *fmt, va_list ap)
356357
continue;
357358

358359
case 's':
360+
if (precision < 0)
361+
precision = INT_MAX;
359362
s = va_arg(args, char *);
363+
if (!s)
364+
s = precision < 6 ? "" : "(null)";
360365
len = strnlen(s, precision);
361366

362367
if (!(flags & LEFT))

0 commit comments

Comments
 (0)