load_uboot_image: don't assume a full header read
authorAndrew Jones <drjones@redhat.com>
Fri, 2 Jun 2017 10:51:46 +0000 (11:51 +0100)
committerPeter Maydell <peter.maydell@linaro.org>
Fri, 2 Jun 2017 10:51:46 +0000 (11:51 +0100)
Don't allow load_uboot_image() to proceed when less bytes than
header-size was read.

Signed-off-by: Andrew Jones <drjones@redhat.com>
Message-id: 20170524091315.20284-1-drjones@redhat.com
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
hw/core/loader.c

index bf17b42cbec24e3a7bfad22fb3397f82262fda39..f72930ca4a41a4886a624c0713326a5eb50e273e 100644 (file)
@@ -611,8 +611,9 @@ static int load_uboot_image(const char *filename, hwaddr *ep, hwaddr *loadaddr,
         return -1;
 
     size = read(fd, hdr, sizeof(uboot_image_header_t));
-    if (size < 0)
+    if (size < sizeof(uboot_image_header_t)) {
         goto out;
+    }
 
     bswap_uboot_header(hdr);