[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-changelog] [xen-unstable] vsprintf: Better size_t input checking, and fix return values of



# HG changeset patch
# User Keir Fraser <keir.fraser@xxxxxxxxxx>
# Date 1222092919 -3600
# Node ID 40233384ffe31a0238743618755a906209c79763
# Parent  c0db74e416626f34cf91b0eefe659bcfe8b43a35
vsprintf: Better size_t input checking, and fix return values of
[v]scnprintf() when size <= 0.

Signed-off-by: Keir Fraser <keir.fraser@xxxxxxxxxx>
---
 xen/common/vsprintf.c |   12 ++++++++----
 1 files changed, 8 insertions(+), 4 deletions(-)

diff -r c0db74e41662 -r 40233384ffe3 xen/common/vsprintf.c
--- a/xen/common/vsprintf.c     Mon Sep 22 14:37:31 2008 +0100
+++ b/xen/common/vsprintf.c     Mon Sep 22 15:15:19 2008 +0100
@@ -272,7 +272,7 @@ int vsnprintf(char *buf, size_t size, co
                                 /* 'z' changed to 'Z' --davidm 1/25/99 */
 
     /* Reject out-of-range values early */
-    BUG_ON((int)size < 0);
+    BUG_ON(((int)size < 0) || ((unsigned int)size != size));
 
     str = buf;
     end = buf + size - 1;
@@ -504,8 +504,10 @@ int vscnprintf(char *buf, size_t size, c
 {
     int i;
 
-    i=vsnprintf(buf,size,fmt,args);
-    return (i >= size) ? (size - 1) : i;
+    i = vsnprintf(buf,size,fmt,args);
+    if (i >= size)
+        i = size - 1;
+    return (i > 0) ? i : 0;
 }
 
 EXPORT_SYMBOL(vscnprintf);
@@ -772,7 +774,9 @@ int scnprintf(char * buf, size_t size, c
     va_start(args, fmt);
     i = vsnprintf(buf, size, fmt, args);
     va_end(args);
-    return (i >= size) ? (size - 1) : i;
+    if (i >= size)
+        i = size - 1;
+    return (i > 0) ? i : 0;
 }
 EXPORT_SYMBOL(scnprintf);
 

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.