From 35921142946225cc292e3954455f2abd4d55daeb Mon Sep 17 00:00:00 2001 From: Ron Yorston Date: Mon, 24 Aug 2020 12:43:20 +0100 Subject: printf: prevent '\0' in format string from truncating output Commit 4a2af48e6 (printf: emit more contiguous text to improve escape sequences) didn't treat an escaped null byte in the format string correctly. The output string was truncated at the null byte. Detect this case, output the partial string and the null byte and carry on. --- coreutils/printf.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'coreutils/printf.c') diff --git a/coreutils/printf.c b/coreutils/printf.c index 45d761d1c..d2b715406 100644 --- a/coreutils/printf.c +++ b/coreutils/printf.c @@ -423,7 +423,15 @@ static char **print_formatted(char *f, char **argv, int *conv_err) printf(s); return saved_argv; /* causes main() to exit */ } - *t++ = bb_process_escape_sequence((const char **)&f); + *t = bb_process_escape_sequence((const char **)&f); + if (*t == '\0') { + printf(s); + bb_putchar(*t); + t = s; + } + else { + ++t; + } f--; break; default: -- cgit v1.2.3-55-g6feb