From patchwork Fri Sep 23 17:38:51 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [U-Boot,3/4] Make printf and vprintf safe from buffer overruns Date: Fri, 23 Sep 2011 07:38:51 -0000 From: Simon Glass X-Patchwork-Id: 116159 Message-Id: <1316799532-20761-4-git-send-email-sjg@chromium.org> To: U-Boot Mailing List Cc: Sonny Rao From: Sonny Rao From: Sonny Rao utilize the added vscnprintf functions to avoid buffer overruns The implementation is fairly dumb in that it doesn't detect that the buffer is too small, but at least will not cause crashes. Signed-off-by: Simon Glass --- common/console.c | 10 +++++----- 1 files changed, 5 insertions(+), 5 deletions(-) diff --git a/common/console.c b/common/console.c index 8c650e0..6057e9a 100644 --- a/common/console.c +++ b/common/console.c @@ -212,7 +212,7 @@ int serial_printf(const char *fmt, ...) /* For this to work, printbuffer must be larger than * anything we ever want to print. */ - i = vsprintf(printbuffer, fmt, args); + i = vscnprintf(printbuffer, CONFIG_SYS_PBSIZE, fmt, args); va_end(args); serial_puts(printbuffer); @@ -281,7 +281,7 @@ int fprintf(int file, const char *fmt, ...) /* For this to work, printbuffer must be larger than * anything we ever want to print. */ - i = vsprintf(printbuffer, fmt, args); + i = vscnprintf(printbuffer, CONFIG_SYS_PBSIZE, fmt, args); va_end(args); /* Send to desired file */ @@ -376,7 +376,7 @@ int printf(const char *fmt, ...) /* For this to work, printbuffer must be larger than * anything we ever want to print. */ - i = vsprintf(printbuffer, fmt, args); + i = vscnprintf(printbuffer, CONFIG_SYS_PBSIZE, fmt, args); va_end(args); /* Print the string */ @@ -392,7 +392,7 @@ int vprintf(const char *fmt, va_list args) /* For this to work, printbuffer must be larger than * anything we ever want to print. */ - i = vsprintf(printbuffer, fmt, args); + i = vscnprintf(printbuffer, CONFIG_SYS_PBSIZE, fmt, args); /* Print the string */ puts(printbuffer); @@ -459,7 +459,7 @@ inline void dbg(const char *fmt, ...) /* For this to work, printbuffer must be larger than * anything we ever want to print. */ - i = vsprintf(printbuffer, fmt, args); + i = vsnprintf(printbuffer, CONFIG_SYS_PBSIZE, fmt, args); va_end(args); if ((screen + sizeof(screen) - 1 - cursor)