aboutsummaryrefslogtreecommitdiffstats
path: root/lib/vsprintf.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@g5.osdl.org>2006-06-28 20:09:34 -0400
committerLinus Torvalds <torvalds@g5.osdl.org>2006-06-28 20:09:34 -0400
commit0a6047eef1c465c38aacfbdab193161b3f0cd144 (patch)
tree3347213ad162a9570d6f4c5cffa1f8db7abb7cba /lib/vsprintf.c
parent27d68a36c4f1ca2fc6be82620843493462c08c51 (diff)
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 <akpm@osdl.org> Acked-by: Jeremy Fitzhardinge <jeremy@goop.org> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Diffstat (limited to 'lib/vsprintf.c')
-rw-r--r--lib/vsprintf.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/lib/vsprintf.c b/lib/vsprintf.c
index 797428afd111..bed7229378f2 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)
489 if (str < end) 489 if (str < end)
490 *str = '\0'; 490 *str = '\0';
491 else 491 else
492 *end = '\0'; 492 end[-1] = '\0';
493 } 493 }
494 /* the trailing null byte doesn't count towards the total */ 494 /* the trailing null byte doesn't count towards the total */
495 return str-buf; 495 return str-buf;