From: Pali Rohár Date: Sun, 29 Jan 2023 16:44:10 +0000 (+0100) Subject: tools: default_image: Verify header size X-Git-Url: http://git.dujemihanovic.xyz/?a=commitdiff_plain;h=3f837b06b76d06189055a0fcdaee4d31c7758d9e;p=u-boot.git tools: default_image: Verify header size Before reading image header, verify that image size is at least size of the image header. Signed-off-by: Pali Rohár Reviewed-by: Simon Glass --- diff --git a/tools/default_image.c b/tools/default_image.c index 0ac3382003..ec723f97b7 100644 --- a/tools/default_image.c +++ b/tools/default_image.c @@ -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