]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
tools: kwbimage: Verify size of v0 image header
authorPali Rohár <pali@kernel.org>
Wed, 11 Aug 2021 08:14:15 +0000 (10:14 +0200)
committerStefan Roese <sr@denx.de>
Wed, 1 Sep 2021 06:07:04 +0000 (08:07 +0200)
Check that extended image header size is not larger than file size.

Signed-off-by: Pali Rohár <pali@kernel.org>
Reviewed-by: Stefan Roese <sr@denx.de>
tools/kwbimage.c

index 542779ed4845c5bb40e79cd5aa1f5f53949d62b9..4709c6d5442753a1365fe15e8dd228a0f692f85e 100644 (file)
@@ -1670,6 +1670,9 @@ static int kwbimage_verify_header(unsigned char *ptr, int image_size,
                if (mhdr->ext & 0x1) {
                        struct ext_hdr_v0 *ext_hdr;
 
+                       if (header_size + sizeof(*ext_hdr) > image_size)
+                               return -FDT_ERR_BADSTRUCTURE;
+
                        ext_hdr = (struct ext_hdr_v0 *)
                                (ptr + sizeof(struct main_hdr_v0));
                        checksum = image_checksum8(ext_hdr,