Skip to content

Commit

Permalink
lib/vsprintf.c: also improve sanity check in bstr_printf()
Browse files Browse the repository at this point in the history
Quoting from 2aa2f9e ("lib/vsprintf.c: improve sanity check in
vsnprintf()"):

    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.

I should have seen this copy-pasted instance back then, but let's just
do it now.

Signed-off-by: Rasmus Villemoes <[email protected]>
Reviewed-by: Andy Shevchenko <[email protected]>
Acked-by: Kees Cook <[email protected]>
Cc: Martin Kletzander <[email protected]>
Cc: Rasmus Villemoes <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
Villemoes authored and torvalds committed Nov 7, 2015
1 parent b006f19 commit 762abb5
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 @@ -2270,7 +2270,7 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
char *str, *end;
const char *args = (const char *)bin_buf;

if (WARN_ON_ONCE((int) size < 0))
if (WARN_ON_ONCE(size > INT_MAX))
return 0;

str = buf;
Expand Down

0 comments on commit 762abb5

Please sign in to comment.