[PATCH] Fix bounds check in vsnprintf, to allow for a 0 size and NULL buffer
authorJeremy Fitzhardinge <jeremy@xensource.com>
Sun, 25 Jun 2006 12:49:17 +0000 (05:49 -0700)
committerLinus Torvalds <torvalds@g5.osdl.org>
Sun, 25 Jun 2006 17:01:23 +0000 (10:01 -0700)
commitf796937a062c7aeb44cd0e75e1586c8543634a7d
treec3cfcbb27e291621e31cff71288f3e82d8b149a8
parent891c668b90ded38cec36f0852c4983573597170d
[PATCH] Fix bounds check in vsnprintf, to allow for a 0 size and NULL buffer

This change allows callers to use a 0-byte buffer and a NULL buffer pointer
with vsnprintf, so it can be used to determine how large the resulting
formatted string will be.

Previously the code effectively treated a size of 0 as a size of 4G (on
32-bit systems), with other checks preventing it from actually trying to
emit the string - but the terminal \0 would still be written, which would
crash if the buffer is NULL.

This change changes the boundary check so that 'end' points to the putative
location of the terminal '\0', which is only written if size > 0.

vsnprintf still allows the buffer size to be set very large, to allow
unbounded buffer sizes (to implement sprintf, etc).

[akpm@osdl.org: fix long-vs-longlong confusion]
Signed-off-by: Jeremy Fitzhardinge <jeremy@xensource.com>
Signed-off-by: Chris Wright <chrisw@sous-sol.org>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
lib/vsprintf.c