Skip to content

bootutil: Fix crash when bootutil_sha_init() is called in loop #2271

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions boot/bootutil/src/image_rsa.c
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ pss_mgf1(uint8_t *mask, const uint8_t *hash)
bootutil_sha_update(&ctx, hash, PSS_HLEN);
bootutil_sha_update(&ctx, counter, 4);
bootutil_sha_finish(&ctx, htmp);
bootutil_sha_drop(&ctx);

counter[3]++;

Expand All @@ -108,8 +109,6 @@ pss_mgf1(uint8_t *mask, const uint8_t *hash)
mask += bytes;
count -= bytes;
}

bootutil_sha_drop(&ctx);
}

/*
Expand Down
3 changes: 1 addition & 2 deletions boot/bootutil/src/image_validate.c
Original file line number Diff line number Diff line change
Expand Up @@ -289,12 +289,11 @@ bootutil_find_key(uint8_t *keyhash, uint8_t keyhash_len)
bootutil_sha_init(&sha_ctx);
bootutil_sha_update(&sha_ctx, key->key, *key->len);
bootutil_sha_finish(&sha_ctx, hash);
bootutil_sha_drop(&sha_ctx);
if (!memcmp(hash, keyhash, keyhash_len)) {
bootutil_sha_drop(&sha_ctx);
return i;
}
}
bootutil_sha_drop(&sha_ctx);
return -1;
}
#else /* !MCUBOOT_HW_KEY */
Expand Down
Loading