Skip to content

Commit

Permalink
lib/vsprintf.c: improve sanity check in vsnprintf()
Browse files Browse the repository at this point in the history
On 64 bit, size may very well be huge even if bit 31 happens to be 0.
Somehow it doesn't feel right that one can pass a 5 GiB buffer but not a
3 GiB one.  So cap at INT_MAX as was probably the intention all along.
This is also the made-up value passed by sprintf and vsprintf.

Signed-off-by: Rasmus Villemoes <[email protected]>
Cc: Jiri Kosina <[email protected]>
Cc: Randy Dunlap <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
Villemoes authored and torvalds committed Feb 13, 2015
1 parent ffbfed0 commit 2aa2f9e
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion lib/vsprintf.c
Original file line number Diff line number Diff line change
Expand Up @@ -1727,7 +1727,7 @@ int vsnprintf(char *buf, size_t size, const char *fmt, va_list args)

/* Reject out-of-range values early. Large positive sizes are
used for unknown buffer sizes. */
if (WARN_ON_ONCE((int) size < 0))
if (WARN_ON_ONCE(size > INT_MAX))
return 0;

str = buf;
Expand Down

0 comments on commit 2aa2f9e

Please sign in to comment.