diff mbox series

[V2,02/10] util: BUG: __swupdate_copy accepts invalid ivt

Message ID 20231204100620.27789-3-Michael.Glembotzki@iris-sensing.com
State Changes Requested
Headers show
Series [V2,01/10] util: BUG: set_aes_key does not fail on invalid aes key or ivt | expand

Commit Message

Michael Glembotzki Dec. 4, 2023, 10:05 a.m. UTC
Signed-off-by: Michael Glembotzki <Michael.Glembotzki@iris-sensing.com>
---
 core/cpio_utils.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
diff mbox series

Patch

diff --git a/core/cpio_utils.c b/core/cpio_utils.c
index 2e5f19a..7049f73 100644
--- a/core/cpio_utils.c
+++ b/core/cpio_utils.c
@@ -514,9 +514,11 @@  static int __swupdate_copy(int fdin, unsigned char *inbuf, void *out, size_t nby
 
 	if (encrypted) {
 		aes_key = get_aes_key();
-		if (imgivt && strlen(imgivt)) {
-			if(ascii_to_bin(ivtbuf, sizeof(ivtbuf), imgivt)) {
-				ERROR("invalid image ivt length");
+		if (imgivt) {
+			if (strlen(imgivt) != (AES_BLK_SIZE * 2) ||
+					is_hex_str(imgivt) ||
+					ascii_to_bin(ivtbuf, sizeof(ivtbuf), imgivt)) {
+				ERROR("invalid image ivt");
 				return -EINVAL;
 			}
 			ivt = ivtbuf;