Return error from boot_find_key instead of asserting
When the hash key length parameter is invalid (bigger than allowed) just
return an error for the caller routines; this will work like a not found
key and allows the removal of assert() code in this module.
Signed-off-by: Fabio Utzig <utzig@apache.org>
diff --git a/boot/bootutil/src/image_validate.c b/boot/bootutil/src/image_validate.c
index a496bc4..b883e44 100644
--- a/boot/bootutil/src/image_validate.c
+++ b/boot/bootutil/src/image_validate.c
@@ -21,7 +21,6 @@
* Modifications are Copyright (c) 2019 Arm Limited.
*/
-#include <assert.h>
#include <stddef.h>
#include <inttypes.h>
#include <string.h>
@@ -183,7 +182,9 @@
const struct bootutil_key *key;
uint8_t hash[32];
- assert(keyhash_len <= 32);
+ if (keyhash_len > 32) {
+ return -1;
+ }
for (i = 0; i < bootutil_key_cnt; i++) {
key = &bootutil_keys[i];