aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRon Yorston <rmy@pobox.com>2020-08-24 12:43:20 +0100
committerRon Yorston <rmy@pobox.com>2020-08-24 12:43:20 +0100
commit35921142946225cc292e3954455f2abd4d55daeb (patch)
treeae2c83f5c9106f6061fe8370d0a28e727940757c
parentdecdf3f58bfdb3fbd2a1dd73a252076373cd5098 (diff)
downloadbusybox-w32-35921142946225cc292e3954455f2abd4d55daeb.tar.gz
busybox-w32-35921142946225cc292e3954455f2abd4d55daeb.tar.bz2
busybox-w32-35921142946225cc292e3954455f2abd4d55daeb.zip
printf: prevent '\0' in format string from truncating outputFRP-3578-g359211429
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.
-rw-r--r--coreutils/printf.c10
1 files changed, 9 insertions, 1 deletions
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)
423 printf(s); 423 printf(s);
424 return saved_argv; /* causes main() to exit */ 424 return saved_argv; /* causes main() to exit */
425 } 425 }
426 *t++ = bb_process_escape_sequence((const char **)&f); 426 *t = bb_process_escape_sequence((const char **)&f);
427 if (*t == '\0') {
428 printf(s);
429 bb_putchar(*t);
430 t = s;
431 }
432 else {
433 ++t;
434 }
427 f--; 435 f--;
428 break; 436 break;
429 default: 437 default: