vsprintf.c cleanups
Subsystems (2)
PATCH 1/1 vsprintf.c cleanups
- Make sprintf call vsnprintf directly
- use INT_MAX for sprintf and vsprintf
vsprintf.c | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-)
lib/vsprintf.c +2 -2
@@ -580,7 +580,7 @@*/ int vsprintf (char *buf,const char *fmt,va_list args) { -return vsnprintf (buf, (~0U )>>1 , fmt, args); +return vsnprintf (buf,INT_MAX , fmt, args); }EXPORT_SYMBOL (vsprintf);
@@ -601,7 +601,7 @@int i;va_start (args, fmt); - i=vsprintf (buf,fmt,args); + i=vsnprintf (buf,INT_MAX , fmt, args);va_end (args);return i; }
Quoted 2 lines · Brian Gerst
- Make sprintf call vsnprintf directly
- useINT_MAXfor sprintf and vsprintf
This is the size limit on what is written. 4GiB sounds a bit extreme...
Signature · 4 lines
Dr. Horst H. von Brand User #22616 counter.li.org Departamento de Informatica Fono: +56 32 654431 Universidad Tecnica Federico Santa Maria +56 32 654239 Casilla 110-V, Valparaiso, Chile Fax: +56 32 797513
Quoted 7 lines · Horst von Brand
Quoted 2 lines · Brian Gerst
- Make sprintf call vsnprintf directly
- useINT_MAXfor sprintf and vsprintfThis is the size limit on what is written. 4GiB sounds a bit extreme...
Sprintf has no limit, which is why it's generally bad to use it. I just replaced an open coded ((~0U)>>1) value with the equivalent INT_MAX.
--
Brian Gerst
Quoted 11 lines · Brian Gerst
Quoted 7 lines · Horst von Brand
Quoted 2 lines · Brian Gerst
- Make sprintf call vsnprintf directly
- useINT_MAXfor sprintf and vsprintfThis is the size limit on what is written. 4GiB sounds a bit extreme...
Sprintf has no limit, which is why it's generally bad to use it. I just replaced an open coded ((~0U)>>1) value with the equivalent
INT_MAX.
I can see the point of using PAGE_SIZE instead; and if someone really wants more than that, he/she should use snprintf with a specified size....
Quoted 10 lines · Brian Gerst
Quoted 6 lines · Horst von Brand
Quoted 2 lines · Brian Gerst
- Make sprintf call vsnprintf directly
- useINT_MAXfor sprintf and vsprintfThis is the size limit on what is written. 4GiB sounds a bit extreme...
Sprintf has no limit, which is why it's generally bad to use it. I just replaced an open coded ((~0U)>>1) value with the equivalent
INT_MAX.
Which is the same as "no limit" in my book. Either you know a limit (in which case vsprintf() is OK) or you don't (in which case vsnprintf() is just obfuscation).
Signature · 4 lines
Dr. Horst H. von Brand User #22616 counter.li.org Departamento de Informatica Fono: +56 32 654431 Universidad Tecnica Federico Santa Maria +56 32 654239 Casilla 110-V, Valparaiso, Chile Fax: +56 32 797513
Quoted 7 lines · Horst von Brand
Quoted 5 lines · Brian Gerst
Quoted 4 lines · Horst von Brand
Quoted 2 lines · Brian Gerst
- Make sprintf call vsnprintf directly
- useINT_MAXfor sprintf and vsprintf
Quoted 8 lines
Quoted 4 lines
Quoted 1 line
This is the size limit on what is written. 4GiB sounds a bit extreme...
Sprintf has no limit, which is why it's generally bad to use it. I just replaced an open coded ((~0U)>>1) value with the equivalent
INT_MAX.Which is the same as "no limit" in my book. Either you know a limit (in which case
vsprintf()is OK) or you don't (in which casevsnprintf()is just obfuscation).
Indeed. So the only place that is allowed to pass the `no limit' value to snprintf() is in the sprintf() wrapper that calls snprintf().
Calls to sprintf() must not be converted to snprintf(..., `no limit', ...), so it's easier to find them when doing buffer overflow audits.
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]
In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds