Skip to content
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

fix(crypto): mac_context_dtor should free MAC #9119

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
7 changes: 6 additions & 1 deletion lib/crypto/c_src/mac.c
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,7 @@ struct mac_context
{
#if defined(HAS_3_0_API)
EVP_MAC_CTX *ctx;
EVP_MAC *mac;
Copy link
Contributor Author

@qzhuyan qzhuyan Dec 2, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should better have a global var instead for different alg.

#else
EVP_MD_CTX *ctx;
#endif
Expand Down Expand Up @@ -531,7 +532,10 @@ static void mac_context_dtor(ErlNifEnv* env, struct mac_context *obj)

if (obj->ctx)
#if defined(HAS_3_0_API)
{
EVP_MAC_CTX_free(obj->ctx);
EVP_MAC_free(obj->mac);
}
#else
EVP_MD_CTX_free(obj->ctx);
#endif
Expand Down Expand Up @@ -730,7 +734,8 @@ ERL_NIF_TERM mac_init_nif(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
if ((obj = enif_alloc_resource(mac_context_rtype, sizeof(struct mac_context))) == NULL)
assign_goto(return_term, err, EXCP_ERROR(env, "Can't allocate mac_context_rtype"));

if (!(obj->ctx = EVP_MAC_CTX_new(mac)))
obj->mac = mac;
if (!(obj->ctx = EVP_MAC_CTX_new(obj->mac)))
assign_goto(return_term, err, EXCP_ERROR(env, "Can't create EVP_MAC_CTX"));

if (!EVP_MAC_init(obj->ctx, key_bin.data, key_bin.size, params))
Expand Down
Loading