From: Linus Torvalds Date: Thu, 29 Jun 2006 00:09:34 +0000 (-0700) Subject: Fix vsnprintf off-by-one bug X-Git-Tag: v2.6.18-rc1~410 X-Git-Url: http://pilppa.com/gitweb/?a=commitdiff_plain;h=0a6047eef1c465c38aacfbdab193161b3f0cd144;p=linux-2.6-omap-h63xx.git Fix vsnprintf off-by-one bug The recent vsnprintf() fix introduced an off-by-one, and it's now possible to overrun the target buffer by one byte. The "end" pointer points to past the end of the buffer, so if we have to truncate the result, it needs to be done though "end[-1]". [ This is just an alternate and simpler patch to one proposed by Andrew and Jeremy, who actually noticed the problem ] Acked-by: Andrew Morton Acked-by: Jeremy Fitzhardinge Signed-off-by: Linus Torvalds --- diff --git a/lib/vsprintf.c b/lib/vsprintf.c index 797428afd11..bed7229378f 100644 --- a/lib/vsprintf.c +++ b/lib/vsprintf.c @@ -489,7 +489,7 @@ int vsnprintf(char *buf, size_t size, const char *fmt, va_list args) if (str < end) *str = '\0'; else - *end = '\0'; + end[-1] = '\0'; } /* the trailing null byte doesn't count towards the total */ return str-buf;