OpenSSL: Fix a memory leak on crypto_hash_init() error path
The EVP_MAC context data needs to be freed on error paths.
Fixes: e31500adea
("OpenSSL: Implement HMAC using the EVP_MAC API")
Signed-off-by: Jouni Malinen <j@w1.fi>
This commit is contained in:
parent
6d19dccf94
commit
c9c2c2d9c7
1 changed files with 6 additions and 5 deletions
|
@ -1362,21 +1362,22 @@ struct crypto_hash * crypto_hash_init(enum crypto_hash_alg alg, const u8 *key,
|
||||||
|
|
||||||
ctx = os_zalloc(sizeof(*ctx));
|
ctx = os_zalloc(sizeof(*ctx));
|
||||||
if (!ctx)
|
if (!ctx)
|
||||||
return NULL;
|
goto fail;
|
||||||
ctx->ctx = EVP_MAC_CTX_new(mac);
|
ctx->ctx = EVP_MAC_CTX_new(mac);
|
||||||
if (!ctx->ctx) {
|
if (!ctx->ctx) {
|
||||||
EVP_MAC_free(mac);
|
|
||||||
os_free(ctx);
|
os_free(ctx);
|
||||||
return NULL;
|
ctx = NULL;
|
||||||
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (EVP_MAC_init(ctx->ctx, key, key_len, params) != 1) {
|
if (EVP_MAC_init(ctx->ctx, key, key_len, params) != 1) {
|
||||||
EVP_MAC_CTX_free(ctx->ctx);
|
EVP_MAC_CTX_free(ctx->ctx);
|
||||||
bin_clear_free(ctx, sizeof(*ctx));
|
bin_clear_free(ctx, sizeof(*ctx));
|
||||||
EVP_MAC_free(mac);
|
ctx = NULL;
|
||||||
return NULL;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fail:
|
||||||
EVP_MAC_free(mac);
|
EVP_MAC_free(mac);
|
||||||
return ctx;
|
return ctx;
|
||||||
#else /* OpenSSL version >= 3.0 */
|
#else /* OpenSSL version >= 3.0 */
|
||||||
|
|
Loading…
Reference in a new issue