Fix doublefree after failure in ossl_siv128_init()

The issue was reported by Ronald Crane from Zippenhop LLC.

Reviewed-by: Neil Horman <nhorman@openssl.org>
Reviewed-by: Shane Lontis <shane.lontis@oracle.com>
Reviewed-by: Paul Dale <ppzgs1@gmail.com>
(Merged from https://github.com/openssl/openssl/pull/28644)

(cherry picked from commit 3185e27624)
This commit is contained in:
Tomas Mraz 2025-09-23 17:00:00 +02:00
parent eea0694955
commit 0f46ba6f5d
1 changed files with 3 additions and 0 deletions

View File

@ -202,9 +202,12 @@ int ossl_siv128_init(SIV128_CONTEXT *ctx, const unsigned char *key, int klen,
|| !EVP_MAC_final(mac_ctx, ctx->d.byte, &out_len, || !EVP_MAC_final(mac_ctx, ctx->d.byte, &out_len,
sizeof(ctx->d.byte))) { sizeof(ctx->d.byte))) {
EVP_CIPHER_CTX_free(ctx->cipher_ctx); EVP_CIPHER_CTX_free(ctx->cipher_ctx);
ctx->cipher_ctx = NULL;
EVP_MAC_CTX_free(ctx->mac_ctx_init); EVP_MAC_CTX_free(ctx->mac_ctx_init);
ctx->mac_ctx_init = NULL;
EVP_MAC_CTX_free(mac_ctx); EVP_MAC_CTX_free(mac_ctx);
EVP_MAC_free(ctx->mac); EVP_MAC_free(ctx->mac);
ctx->mac = NULL;
return 0; return 0;
} }
EVP_MAC_CTX_free(mac_ctx); EVP_MAC_CTX_free(mac_ctx);