Skip to content

Commit 39a5af8

Browse files
committed
Free hd_context if error.
Signed-off-by: Pol Henarejos <[email protected]>
1 parent 28c63a5 commit 39a5af8

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

src/hsm/cmd_cipher_sym.c

+1
Original file line numberDiff line numberDiff line change
@@ -664,6 +664,7 @@ int cmd_cipher_sym() {
664664
secret[64] = { 0 };
665665
mbedtls_aes_init(&ctx);
666666
if (hd_keytype != 0x3) {
667+
mbedtls_ecdsa_free(&hd_context);
667668
return SW_INCORRECT_PARAMS();
668669
}
669670
key_size = 32;

src/hsm/cmd_signature.c

+3-1
Original file line numberDiff line numberDiff line change
@@ -284,11 +284,13 @@ int cmd_signature() {
284284
}
285285
else if (p2 == ALGO_HD) {
286286
size_t olen = 0;
287-
uint8_t buf[MBEDTLS_ECDSA_MAX_LEN];
287+
uint8_t buf[MBEDTLS_ECDSA_MAX_LEN] = {0};
288288
if (hd_context.grp.id == MBEDTLS_ECP_DP_NONE) {
289+
mbedtls_ecdsa_free(&hd_context);
289290
return SW_CONDITIONS_NOT_SATISFIED();
290291
}
291292
if (hd_keytype != 0x1 && hd_keytype != 0x2) {
293+
mbedtls_ecdsa_free(&hd_context);
292294
return SW_INCORRECT_PARAMS();
293295
}
294296
md = MBEDTLS_MD_SHA256;

0 commit comments

Comments
 (0)