]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
tools: kwboot: Explicitly check against size of struct main_hdr_v1
authorMarek Behún <marek.behun@nic.cz>
Fri, 24 Sep 2021 21:07:04 +0000 (23:07 +0200)
committerStefan Roese <sr@denx.de>
Fri, 1 Oct 2021 09:07:13 +0000 (11:07 +0200)
Explicitly check the image size against size of struct main_hdr_v1.
This way the check is more readable, since the `hdrsz` variable
may semantically contain another value.

Signed-off-by: Marek Behún <marek.behun@nic.cz>
Reviewed-by: Stefan Roese <sr@denx.de>
tools/kwboot.c

index 4fae44c46e983094f7cb2640fcfa090b74fb6d48..77bf5cb80b61b73815ceaf72a9c09d16ca6ebe06 100644 (file)
@@ -820,14 +820,14 @@ kwboot_img_patch_hdr(void *img, size_t *size)
        struct main_hdr_v1 *hdr;
        uint32_t srcaddr;
        uint8_t csum;
-       size_t hdrsz = sizeof(*hdr);
+       size_t hdrsz;
        int image_ver;
        int is_secure;
 
        rc = -1;
        hdr = img;
 
-       if (*size < hdrsz) {
+       if (*size < sizeof(struct main_hdr_v1)) {
                errno = EINVAL;
                goto out;
        }