]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
tools: default_image: Verify header size
authorPali Rohár <pali@kernel.org>
Sun, 29 Jan 2023 16:44:10 +0000 (17:44 +0100)
committerTom Rini <trini@konsulko.com>
Mon, 6 Feb 2023 19:35:14 +0000 (14:35 -0500)
Before reading image header, verify that image size is at least size of
the image header.

Signed-off-by: Pali Rohár <pali@kernel.org>
Reviewed-by: Simon Glass <sjg@chromium.org>
tools/default_image.c

index 0ac3382003d5878c31b05a955d914bd04ea0a7a6..ec723f97b71cf44a36aa73ea59c8c27116b1a399 100644 (file)
@@ -50,6 +50,12 @@ static int image_verify_header(unsigned char *ptr, int image_size,
        struct legacy_img_hdr header;
        struct legacy_img_hdr *hdr = &header;
 
+       if (image_size < sizeof(struct legacy_img_hdr)) {
+               debug("%s: Bad image size: \"%s\" is no valid image\n",
+                     params->cmdname, params->imagefile);
+               return -FDT_ERR_BADSTRUCTURE;
+       }
+
        /*
         * create copy of header so that we can blank out the
         * checksum field for checking - this can't be done