Skip to content

Commit f664d8c

Browse files
committed
bootutil: Fix crash when bootutil_sha_init() is called in loop
For mynewt hardware implementation of hash functionality calling bootutil_sha_init() in a loop without call to bootutil_sha_drop() result in a failure. In two places where bootutil_sha_drop() was called after the loop, call is move into the loop to match calls to bootutil_sha_init(). This will not impact default implementation where calling bootutil_sha_drop() in a loop does not change anything. Signed-off-by: Jerzy Kasenberg <[email protected]>
1 parent 6cbea0a commit f664d8c

File tree

2 files changed

+2
-4
lines changed

2 files changed

+2
-4
lines changed

boot/bootutil/src/image_rsa.c

+1-2
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ pss_mgf1(uint8_t *mask, const uint8_t *hash)
9797
bootutil_sha_update(&ctx, hash, PSS_HLEN);
9898
bootutil_sha_update(&ctx, counter, 4);
9999
bootutil_sha_finish(&ctx, htmp);
100+
bootutil_sha_drop(&ctx);
100101

101102
counter[3]++;
102103

@@ -108,8 +109,6 @@ pss_mgf1(uint8_t *mask, const uint8_t *hash)
108109
mask += bytes;
109110
count -= bytes;
110111
}
111-
112-
bootutil_sha_drop(&ctx);
113112
}
114113

115114
/*

boot/bootutil/src/image_validate.c

+1-2
Original file line numberDiff line numberDiff line change
@@ -289,12 +289,11 @@ bootutil_find_key(uint8_t *keyhash, uint8_t keyhash_len)
289289
bootutil_sha_init(&sha_ctx);
290290
bootutil_sha_update(&sha_ctx, key->key, *key->len);
291291
bootutil_sha_finish(&sha_ctx, hash);
292+
bootutil_sha_drop(&sha_ctx);
292293
if (!memcmp(hash, keyhash, keyhash_len)) {
293-
bootutil_sha_drop(&sha_ctx);
294294
return i;
295295
}
296296
}
297-
bootutil_sha_drop(&sha_ctx);
298297
return -1;
299298
}
300299
#else /* !MCUBOOT_HW_KEY */

0 commit comments

Comments
 (0)