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 <pali@kernel.org>
Reviewed-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
Pali Rohár 2023-01-29 17:44:10 +01:00 committed by Tom Rini
parent afd82187b5
commit 3f837b06b7

View 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