diff options
author | Phillip Lougher <phillip@lougher.demon.co.uk> | 2011-11-11 14:30:36 +0100 |
---|---|---|
committer | Phillip Lougher <phillip@lougher.demon.co.uk> | 2011-11-11 14:30:36 +0100 |
commit | 072eb7aba6c987d81f100c992fb5097d9159aee5 (patch) | |
tree | c0c6add1ea84d812f409d5a0a61a61ba7738a751 /xen/common/bunzip2.c | |
parent | 8901ea9184c3c02232f9c33a6daeeeed827c645e (diff) | |
download | xen-072eb7aba6c987d81f100c992fb5097d9159aee5.tar.gz xen-072eb7aba6c987d81f100c992fb5097d9159aee5.tar.bz2 xen-072eb7aba6c987d81f100c992fb5097d9159aee5.zip |
bzip2: Add missing checks for malloc returning NULL
From: Phillip Lougher <phillip@lougher.demon.co.uk>
Signed-off-by: Phillip Lougher <phillip@lougher.demon.co.uk>
Signed-off-by: Jan Beulich <jbeulich@suse.com>
Acked-by: Keir Fraser <keir@xen.org>
Committed-by: Jan Beulich <jbeulich@suse.com>
Diffstat (limited to 'xen/common/bunzip2.c')
-rw-r--r-- | xen/common/bunzip2.c | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/xen/common/bunzip2.c b/xen/common/bunzip2.c index eaf920231a..d87bdcff9e 100644 --- a/xen/common/bunzip2.c +++ b/xen/common/bunzip2.c @@ -629,6 +629,8 @@ static int INIT start_bunzip(struct bunzip_data **bdp, void *inbuf, int len, /* 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 @@ static int INIT start_bunzip(struct bunzip_data **bdp, void *inbuf, int len, 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 @@ STATIC int INIT bunzip2(unsigned char *buf, unsigned int len, if (!outbuf) { error("Could not allocate output bufer"); - return -1; + return RETVAL_OUT_OF_MEMORY; } if (buf) inbuf = buf; @@ -685,6 +689,7 @@ STATIC int INIT bunzip2(unsigned char *buf, unsigned int len, 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 @@ STATIC int INIT bunzip2(unsigned char *buf, unsigned int len, } 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: |