]> xenbits.xensource.com Git - people/liuw/libxenctrl-split/libvirt.git/commitdiff
buf: protect against integer overflow
authorEric Blake <eblake@redhat.com>
Fri, 24 Jun 2011 20:04:04 +0000 (14:04 -0600)
committerEric Blake <eblake@redhat.com>
Fri, 24 Jun 2011 22:01:56 +0000 (16:01 -0600)
It's unlikely that we'll ever want to escape a string as long as
INT_MAX/6, but adding this check can't hurt.

* src/util/buf.c (virBufferEscapeSexpr, virBufferEscapeString):
Check for (unlikely) overflow.

src/util/buf.c

index 750e2770b1cf24b0a1cf9f4ead00ae66bc6bc123..500248683e6df21a53e2d22497c655a42059c0e5 100644 (file)
@@ -311,7 +311,8 @@ virBufferEscapeString(const virBufferPtr buf, const char *format, const char *st
         return;
     }
 
-    if (VIR_ALLOC_N(escaped, 6 * len + 1) < 0) {
+    if (xalloc_oversized(6, len) ||
+        VIR_ALLOC_N(escaped, 6 * len + 1) < 0) {
         virBufferSetError(buf);
         return;
     }
@@ -398,7 +399,8 @@ virBufferEscapeSexpr(const virBufferPtr buf,
         return;
     }
 
-    if (VIR_ALLOC_N(escaped, 2 * len + 1) < 0) {
+    if (xalloc_oversized(2, len) ||
+        VIR_ALLOC_N(escaped, 2 * len + 1) < 0) {
         virBufferSetError(buf);
         return;
     }