WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-changelog

[Xen-changelog] [xen-unstable] vsprintf: Better size_t input checking, a

To: xen-changelog@xxxxxxxxxxxxxxxxxxx
Subject: [Xen-changelog] [xen-unstable] vsprintf: Better size_t input checking, and fix return values of
From: Xen patchbot-unstable <patchbot-unstable@xxxxxxxxxxxxxxxxxxx>
Date: Mon, 22 Sep 2008 11:20:13 -0700
Delivery-date: Mon, 22 Sep 2008 11:20:21 -0700
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
List-help: <mailto:xen-changelog-request@lists.xensource.com?subject=help>
List-id: BK change log <xen-changelog.lists.xensource.com>
List-post: <mailto:xen-changelog@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/mailman/listinfo/xen-changelog>, <mailto:xen-changelog-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/mailman/listinfo/xen-changelog>, <mailto:xen-changelog-request@lists.xensource.com?subject=unsubscribe>
Reply-to: xen-devel@xxxxxxxxxxxxxxxxxxx
Sender: xen-changelog-bounces@xxxxxxxxxxxxxxxxxxx
# 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

<Prev in Thread] Current Thread [Next in Thread>
  • [Xen-changelog] [xen-unstable] vsprintf: Better size_t input checking, and fix return values of, Xen patchbot-unstable <=