[U-Boot] [PATCH 3/4] Make printf and vprintf safe from buffer overruns

Simon Glass
2011-09-23T20:41:50Z

Hi Mike,

On Fri, Sep 23, 2011 at 1:31 PM, Mike Frysinger <vapier@gentoo.org> wrote:
> On Friday, September 23, 2011 13:38:51 Simon Glass wrote:
>> --- 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);
>
> i think sizeof(printbuffer) would be better. ?same goes for all the other
> changes here.
> -mike
>

Yes, indeed. Could we go as far as removing CONFIG_SYS_PBSIZE, and
just use a standard value?

Regards,
Simon