libxc: don't read uninitialized size value in xc_read_image
authorMatthew Daley <mattjd@gmail.com>
Wed, 30 Oct 2013 07:51:42 +0000 (20:51 +1300)
committerIan Campbell <ian.campbell@citrix.com>
Thu, 31 Oct 2013 22:13:52 +0000 (22:13 +0000)
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 <mattjd@gmail.com>
Reviewed-by: Andrew Cooper <andrew.cooper3@citrix.com>
Acked-by: Ian Campbell <ian.campbell@citrix.com>
tools/libxc/xg_private.c

index 8fa068ef439e0c5f7b88b779c40e938b073c1c15..a914068fc35e6bafb73641807dceb1aae7d20572 100644 (file)
@@ -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);