瀏覽代碼

tools: kwbimage: Verify supported image version

Only image versions 0 and 1 are supported. Verify it in
kwbimage_verify_header() function.

Signed-off-by: Pali Rohár <pali@kernel.org>
Reviewed-by: Stefan Roese <sr@denx.de>
Pali Rohár 2 年之前
父節點
當前提交
b984056fa6
共有 1 個文件被更改,包括 3 次插入3 次删除
  1. 3 3
      tools/kwbimage.c

+ 3 - 3
tools/kwbimage.c

@@ -1678,9 +1678,7 @@ static int kwbimage_verify_header(unsigned char *ptr, int image_size,
 			if (checksum != ext_hdr->checksum)
 				return -FDT_ERR_BADSTRUCTURE;
 		}
-	}
-
-	if (image_version((void *)ptr) == 1) {
+	} else if (image_version((void *)ptr) == 1) {
 		struct main_hdr_v1 *mhdr = (struct main_hdr_v1 *)ptr;
 		uint32_t offset;
 		uint32_t size;
@@ -1750,6 +1748,8 @@ static int kwbimage_verify_header(unsigned char *ptr, int image_size,
 		if (image_checksum32(ptr + offset, size - 4) !=
 		    *(uint32_t *)(ptr + offset + size - 4))
 			return -FDT_ERR_BADSTRUCTURE;
+	} else {
+		return -FDT_ERR_BADSTRUCTURE;
 	}
 
 	return 0;