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

[Xen-changelog] [xen-unstable] bzip2: Add missing checks for malloc returning NULL



# HG changeset patch
# User Phillip Lougher <phillip@xxxxxxxxxxxxxxxxxxx>
# Date 1321018236 -3600
# Node ID 57db49cf118889792d32d22e80129604b4ca04af
# Parent  b2891cecc67630767cdf81a08ee82ed5c9929a45
bzip2: Add missing checks for malloc returning NULL

From: Phillip Lougher <phillip@xxxxxxxxxxxxxxxxxxx>

Signed-off-by: Phillip Lougher <phillip@xxxxxxxxxxxxxxxxxxx>
Signed-off-by: Jan Beulich <jbeulich@xxxxxxxx>
Acked-by: Keir Fraser <keir@xxxxxxx>
Committed-by: Jan Beulich <jbeulich@xxxxxxxx>
---


diff -r b2891cecc676 -r 57db49cf1188 xen/common/bunzip2.c
--- a/xen/common/bunzip2.c      Fri Nov 11 14:29:21 2011 +0100
+++ b/xen/common/bunzip2.c      Fri Nov 11 14:30:36 2011 +0100
@@ -629,6 +629,8 @@
 
        /* Allocate bunzip_data.  Most fields initialize to zero. */
        bd = *bdp = malloc(i);
+       if (!bd)
+               return RETVAL_OUT_OF_MEMORY;
        memset(bd, 0, sizeof(struct bunzip_data));
        /* Setup input buffer */
        bd->inbuf = inbuf;
@@ -656,6 +658,8 @@
        bd->dbufSize = 100000*(i-BZh0);
 
        bd->dbuf = large_malloc(bd->dbufSize * sizeof(int));
+       if (!bd->dbuf)
+               return RETVAL_OUT_OF_MEMORY;
        return RETVAL_OK;
 }
 
@@ -677,7 +681,7 @@
 
        if (!outbuf) {
                error("Could not allocate output bufer");
-               return -1;
+               return RETVAL_OUT_OF_MEMORY;
        }
        if (buf)
                inbuf = buf;
@@ -685,6 +689,7 @@
                inbuf = malloc(BZIP2_IOBUF_SIZE);
        if (!inbuf) {
                error("Could not allocate input bufer");
+               i = RETVAL_OUT_OF_MEMORY;
                goto exit_0;
        }
        i = start_bunzip(&bd, inbuf, len, fill);
@@ -711,11 +716,14 @@
        } else if (i == RETVAL_UNEXPECTED_OUTPUT_EOF) {
                error("Compressed file ends unexpectedly");
        }
+       if (!bd)
+               goto exit_1;
        if (bd->dbuf)
                large_free(bd->dbuf);
        if (pos)
                *pos = bd->inbufPos;
        free(bd);
+exit_1:
        if (!buf)
                free(inbuf);
 exit_0:

_______________________________________________
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®.