Skip to content

Commit

Permalink
Fix leaking EVP_MAC_CTX in one shot
Browse files Browse the repository at this point in the history
  • Loading branch information
vcsjones authored Sep 6, 2024
1 parent cf8cbe9 commit 5a6d100
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions src/native/libs/System.Security.Cryptography.Native/pal_evp_mac.c
Original file line number Diff line number Diff line change
Expand Up @@ -369,32 +369,35 @@ int32_t CryptoNative_EvpMacOneShot(EVP_MAC* mac,

params[i] = OSSL_PARAM_construct_end();

int32_t ret = 0;

if (!EVP_MAC_init(ctx, NULL, 0, params))
{
EVP_MAC_CTX_free(ctx);
return 0;
goto done;
}

if (!EVP_MAC_update(ctx, data, dataLengthT))
{
EVP_MAC_CTX_free(ctx);
return 0;
goto done;
}

size_t written = 0;

if (!EVP_MAC_final(ctx, destination, &written, macLengthT))
{
EVP_MAC_CTX_free(ctx);
return 0;
goto done;
}

if (written != macLengthT)
{
return -3;
ret = -3;
goto done;
}

return 1;
ret = 1;
done:
EVP_MAC_CTX_free(ctx);
return ret;
}
#else
(void)mac;
Expand Down

0 comments on commit 5a6d100

Please sign in to comment.