]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
tools: kwbimage: Verify size of image data
authorPali Rohár <pali@kernel.org>
Wed, 11 Aug 2021 08:14:16 +0000 (10:14 +0200)
committerStefan Roese <sr@denx.de>
Wed, 1 Sep 2021 06:07:04 +0000 (08:07 +0200)
Part of image data is 4 byte checksum, so every image must contain at least
4 bytes. Verify it to prevent memory corruptions.

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

index 4709c6d5442753a1365fe15e8dd228a0f692f85e..f47e52f13a9a0db8580560f9150aa786e8b3524a 100644 (file)
@@ -1745,7 +1745,7 @@ static int kwbimage_verify_header(unsigned char *ptr, int image_size,
                        return -FDT_ERR_BADSTRUCTURE;
 
                size = le32_to_cpu(mhdr->blocksize);
-               if (offset + size > image_size || size % 4 != 0)
+               if (size < 4 || offset + size > image_size || size % 4 != 0)
                        return -FDT_ERR_BADSTRUCTURE;
 
                if (image_checksum32(ptr + offset, size - 4) !=