From: Matthew Daley Date: Wed, 30 Oct 2013 07:51:42 +0000 (+1300) Subject: libxc: don't read uninitialized size value in xc_read_image X-Git-Tag: archive/raspbian/4.8.0-1+rpi1~1^2~6088 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=bbf891bcd1841bc61d0726d11988b8c9bf8d6757;p=xen.git libxc: don't read uninitialized size value in xc_read_image This error case can only be triggered by gzread returning 0 (and having not read anything), so move it there. Coverity-ID: 1056076 Signed-off-by: Matthew Daley Reviewed-by: Andrew Cooper Acked-by: Ian Campbell --- diff --git a/tools/libxc/xg_private.c b/tools/libxc/xg_private.c index 8fa068ef43..a914068fc3 100644 --- a/tools/libxc/xg_private.c +++ b/tools/libxc/xg_private.c @@ -71,6 +71,12 @@ char *xc_read_image(xc_interface *xch, image = NULL; goto out; case 0: /* EOF */ + if ( *size == 0 ) + { + PERROR("Could not read kernel image"); + free(image); + image = NULL; + } goto out; default: *size += bytes; @@ -80,13 +86,7 @@ char *xc_read_image(xc_interface *xch, #undef CHUNK out: - if ( *size == 0 ) - { - PERROR("Could not read kernel image"); - free(image); - image = NULL; - } - else if ( image ) + if ( image ) { /* Shrink allocation to fit image. */ tmp = realloc(image, *size);