[PULL,02/27] load_uboot_image: don't assume a full header read

Message ID 1496337035-30213-3-git-send-email-peter.maydell@linaro.org
State Not Applicable
Headers show
Series
  • target-arm queue
Related show

Commit Message

Peter Maydell June 1, 2017, 5:10 p.m.
From: Andrew Jones <drjones@redhat.com>


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 | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

-- 
2.7.4

Patch hide | download patch | download mbox

diff --git a/hw/core/loader.c b/hw/core/loader.c
index bf17b42..f72930c 100644
--- a/hw/core/loader.c
+++ b/hw/core/loader.c
@@ -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);