mirror of
https://github.com/smaeul/u-boot.git
synced 2025-11-18 01:40:58 +00:00
tools: kwboot: Validate optional kwbimage v1 headers
Before starting parsing of kwbimage, first validate that all optional v1 headers and correct. This prevents kwboot crashes on invalid input. Signed-off-by: Pali Rohár <pali@kernel.org>
This commit is contained in:
parent
7665ed2fa0
commit
53ee6ec827
@ -1939,6 +1939,7 @@ static int
|
||||
kwboot_img_patch(void *img, size_t *size, int baudrate)
|
||||
{
|
||||
struct main_hdr_v1 *hdr;
|
||||
struct opt_hdr_v1 *ohdr;
|
||||
uint32_t srcaddr;
|
||||
uint8_t csum;
|
||||
size_t hdrsz;
|
||||
@ -1990,6 +1991,13 @@ kwboot_img_patch(void *img, size_t *size, int baudrate)
|
||||
*size < le32_to_cpu(hdr->srcaddr) + le32_to_cpu(hdr->blocksize))
|
||||
goto err;
|
||||
|
||||
for_each_opt_hdr_v1 (ohdr, hdr) {
|
||||
if (!opt_hdr_v1_valid_size(ohdr, (const uint8_t *)hdr + hdrsz)) {
|
||||
fprintf(stderr, "Invalid optional image header\n");
|
||||
goto err;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* The 32-bit data checksum is optional for UART image. If it is not
|
||||
* present (checksum detected as invalid) then grow data part of the
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user