Skip to content

Commit f97ca2c

Browse files
nivedita76ardbiesheuvel
authored andcommitted
efi/printf: Abort on invalid format
If we get an invalid conversion specifier, bail out instead of trying to fix it up. The format string likely has a typo or assumed we support something that we don't, in either case the remaining arguments won't match up with the remaining format string. Signed-off-by: Arvind Sankar <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Ard Biesheuvel <[email protected]>
1 parent 6c4bcd8 commit f97ca2c

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

drivers/firmware/efi/libstub/vsprintf.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -359,12 +359,13 @@ int vsprintf(char *buf, const char *fmt, va_list ap)
359359
break;
360360

361361
default:
362-
*str++ = '%';
363-
if (*fmt)
364-
*str++ = *fmt;
365-
else
366-
--fmt;
367-
continue;
362+
/*
363+
* Bail out if the conversion specifier is invalid.
364+
* There's probably a typo in the format string and the
365+
* remaining specifiers are unlikely to match up with
366+
* the arguments.
367+
*/
368+
goto fail;
368369
}
369370
if (*fmt == 'p') {
370371
num = (unsigned long)va_arg(args, void *);
@@ -434,6 +435,7 @@ int vsprintf(char *buf, const char *fmt, va_list ap)
434435
while (field_width-- > 0)
435436
*str++ = ' ';
436437
}
438+
fail:
437439
*str = '\0';
438440

439441
va_end(args);

0 commit comments

Comments
 (0)