diff options
author | Pali Rohár <pali@kernel.org> | 2023-01-29 17:44:10 +0100 |
---|---|---|
committer | Tom Rini <trini@konsulko.com> | 2023-02-06 14:35:14 -0500 |
commit | 3f837b06b76d06189055a0fcdaee4d31c7758d9e (patch) | |
tree | 509205509f593952812ac15c4aaedf5f0572da87 /tools | |
parent | afd82187b549e3bebc2ae02dc2914f8a43418ec4 (diff) | |
download | u-boot-3f837b06b76d06189055a0fcdaee4d31c7758d9e.tar.gz u-boot-3f837b06b76d06189055a0fcdaee4d31c7758d9e.tar.bz2 u-boot-3f837b06b76d06189055a0fcdaee4d31c7758d9e.zip |
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>
Diffstat (limited to 'tools')
-rw-r--r-- | tools/default_image.c | 6 |
1 files changed, 6 insertions, 0 deletions
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 |