Skip to content

Commit

Permalink
Fix cms.c mem leak
Browse files Browse the repository at this point in the history
  • Loading branch information
guanzhi committed Dec 12, 2023
1 parent 8974e0f commit 10e0221
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/cms.c
Original file line number Diff line number Diff line change
Expand Up @@ -356,12 +356,14 @@ int cms_enced_content_info_encrypt_to_der(

if (enc_algor != OID_sm4_cbc || keylen != 16 || ivlen != 16) {
error_print();
if (enced_content) free(enced_content);
return -1;
}

sm4_set_encrypt_key(&sm4_key, key);
if (sm4_cbc_padding_encrypt(&sm4_key, iv, content, content_len,
enced_content, &enced_content_len) != 1) {
if (enced_content) free(enced_content);
memset(&sm4_key, 0, sizeof(SM4_KEY));
error_print();
return -1;
Expand All @@ -373,9 +375,12 @@ int cms_enced_content_info_encrypt_to_der(
shared_info1, shared_info1_len,
shared_info2, shared_info2_len,
out, outlen)) != 1) {
if (enced_content) free(enced_content);
if (ret < 0) error_print();
return ret;
}

free(enced_content); //FIXME: use goto end to clean enced_content
return 1;
}

Expand Down

0 comments on commit 10e0221

Please sign in to comment.