Skip to content

Commit

Permalink
Fix leaking EVP_MAC_CTX in one shot (#107471)
Browse files Browse the repository at this point in the history
Co-authored-by: Kevin Jones <kevin@vcsjones.com>
  • Loading branch information
github-actions[bot] and vcsjones authored Sep 9, 2024
1 parent 7b91da6 commit c608194
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 c608194

Please sign in to comment.