public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] lib: vsprintf: fix invalid arg check
@ 2010-11-10 20:38 Vasiliy Kulikov
  2010-11-10 21:08 ` Andrew Morton
  0 siblings, 1 reply; 8+ messages in thread
From: Vasiliy Kulikov @ 2010-11-10 20:38 UTC (permalink / raw)
  To: kernel-janitors
  Cc: Andrew Morton, André Goddard Rosa, Joe Perches,
	Frederic Weisbecker, Bjorn Helgaas, linux-kernel

"size" is size_t.  If we want to check whether it was underflowed
then we should cast it to ssize_t instead of int.  When
sizeof(size_t) > sizeof(int) the code sees UINT_MAX as underflow,
but it is not.

Signed-off-by: Vasiliy Kulikov <segooon@gmail.com>
---
 Compile tested.

 lib/vsprintf.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/lib/vsprintf.c b/lib/vsprintf.c
index c150d3d..e7cf674 100644
--- a/lib/vsprintf.c
+++ b/lib/vsprintf.c
@@ -1290,7 +1290,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((ssize_t) size < 0))
 		return 0;
 
 	str = buf;
-- 
1.7.0.4


^ permalink raw reply related	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2010-11-12 17:42 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-11-10 20:38 [PATCH] lib: vsprintf: fix invalid arg check Vasiliy Kulikov
2010-11-10 21:08 ` Andrew Morton
2010-11-10 21:38   ` David Rientjes
2010-11-11  8:34     ` Vasiliy Kulikov
2010-11-11 20:38       ` David Rientjes
2010-11-11 21:02         ` Vasiliy Kulikov
2010-11-11 21:34           ` David Rientjes
2010-11-12 17:42             ` Vasiliy Kulikov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox