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

Simon Glass sjg at chromium.org
Sat Sep 24 01:06:48 CEST 2011


Hi Mike,

On Fri, Sep 23, 2011 at 3:36 PM, Mike Frysinger <vapier at gentoo.org> wrote:
> On Friday, September 23, 2011 16:41:50 Simon Glass wrote:
>> On Fri, Sep 23, 2011 at 1:31 PM, Mike Frysinger 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?
>
> in the context of I/O funcs, CONFIG_SYS_PBSIZE is the current standard
> -mike
>

OK - is there a reason why boards can redefine this? Many many boards
do. It seems like something that should just be given a sensible
value.

Regards,
Simon


More information about the U-Boot mailing list