From mboxrd@z Thu Jan 1 00:00:00 1970 From: Matthew Daley Subject: [PATCH 06/29] libxc: don't read uninitialized size value in xc_read_image Date: Wed, 30 Oct 2013 20:51:42 +1300 Message-ID: <1383119525-26033-7-git-send-email-mattjd@gmail.com> References: <1383119525-26033-1-git-send-email-mattjd@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <1383119525-26033-1-git-send-email-mattjd@gmail.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: xen-devel@lists.xen.org Cc: Matthew Daley , Ian Jackson , Ian Campbell , Stefano Stabellini List-Id: xen-devel@lists.xenproject.org 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 --- tools/libxc/xg_private.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/tools/libxc/xg_private.c b/tools/libxc/xg_private.c index 8fa068e..a914068 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); -- 1.7.10.4