From: Pali Rohár Date: Fri, 23 Jul 2021 09:14:21 +0000 (+0200) Subject: tools: kwboot: Check for v1 header size X-Git-Url: http://git.dujemihanovic.xyz/?a=commitdiff_plain;h=825a2ca023202f73a09660db7a49ac1109917ce8;p=u-boot.git tools: kwboot: Check for v1 header size Too small invalid headers may cause kwboot to crash. Check for header size of v1 images. Signed-off-by: Pali Rohár Reviewed-by: Marek Behún Reviewed-by: Stefan Roese Reviewed-by: Chris Packham Tested-by: Chris Packham --- diff --git a/tools/kwboot.c b/tools/kwboot.c index c0ac4ce19e..1d32c1b7ad 100644 --- a/tools/kwboot.c +++ b/tools/kwboot.c @@ -645,6 +645,11 @@ kwboot_img_patch_hdr(void *img, size_t size) else hdrsz = KWBHEADER_V1_SIZE(hdr); + if (size < hdrsz) { + errno = EINVAL; + goto out; + } + csum = kwboot_img_csum8(hdr, hdrsz) - hdr->checksum; if (csum != hdr->checksum) { errno = EINVAL;