aboutsummaryrefslogtreecommitdiff
path: root/tools/kwbimage.c
diff options
context:
space:
mode:
authorPali Rohár2021-08-11 10:14:16 +0200
committerStefan Roese2021-09-01 08:07:04 +0200
commita008dbaa8ce2d4142e17780177faa381fd59bb4e (patch)
treec6ac3f7d4aac983b91183eb39021b98c33e6e4f7 /tools/kwbimage.c
parent33a0af2d8041b027cfbf6ab23c93026339aff142 (diff)
tools: kwbimage: Verify size of image data
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>
Diffstat (limited to 'tools/kwbimage.c')
-rw-r--r--tools/kwbimage.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/tools/kwbimage.c b/tools/kwbimage.c
index 4709c6d5442..f47e52f13a9 100644
--- a/tools/kwbimage.c
+++ b/tools/kwbimage.c
@@ -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) !=