diff options
author | ben <ben@FreeBSD.org> | 2000-12-21 22:21:38 +0000 |
---|---|---|
committer | ben <ben@FreeBSD.org> | 2000-12-21 22:21:38 +0000 |
commit | fde2e04b05f535a43f936f079e1e0c15b351702c (patch) | |
tree | d3ab4fbff7f7be45bc0870ea71661425a294d192 | |
parent | 4b6a7bddad70a11b35893cc1825a768e53fb28c7 (diff) | |
download | FreeBSD-src-fde2e04b05f535a43f936f079e1e0c15b351702c.zip FreeBSD-src-fde2e04b05f535a43f936f079e1e0c15b351702c.tar.gz |
Fix printf(1) for cases where a long string with no format specifiers is
followed by a %d (probably others too) format specifier.
Reviewed by: audit
-rw-r--r-- | usr.bin/printf/printf.c | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/usr.bin/printf/printf.c b/usr.bin/printf/printf.c index 62b8912..4b01b4a 100644 --- a/usr.bin/printf/printf.c +++ b/usr.bin/printf/printf.c @@ -60,6 +60,7 @@ static const char rcsid[] = #ifdef SHELL #define main printfcmd #include "bltin/bltin.h" +#include "memalloc.h" #else #define warnx1(a, b, c) warnx(a) #define warnx2(a, b, c) warnx(a, b) @@ -247,12 +248,23 @@ mklong(str, ch) char *str; int ch; { - static char copy[64]; - int len; + static char *copy; + static size_t copy_size; + size_t len, newlen; + char *newcopy; len = strlen(str) + 2; - if (len > sizeof copy) - return NULL; + if (len > copy_size) { + newlen = ((len + 1023) >> 10) << 10; +#ifdef SHELL + if ((newcopy = ckrealloc(copy, newlen)) == NULL) +#else + if ((newcopy = realloc(copy, newlen)) == NULL) +#endif + return (NULL); + copy = newcopy; + copy_size = newlen; + } memmove(copy, str, len - 3); copy[len - 3] = 'q'; |