]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-dcrypt: ctx_hmac_init() - Fix memory leak if MAC initialization failed
authorTimo Sirainen <timo.sirainen@open-xchange.com>
Fri, 2 Aug 2024 11:15:23 +0000 (14:15 +0300)
committerTimo Sirainen <timo.sirainen@open-xchange.com>
Fri, 2 Aug 2024 11:15:23 +0000 (14:15 +0300)
src/lib-dcrypt/dcrypt-openssl1.c
src/lib-dcrypt/dcrypt-openssl3.c

index 68671b457a3a93b8d64d95b67b6be159dbaef398..36bc017a3672825f1a1c2f41a290b5b9ec2c7f68 100644 (file)
@@ -694,8 +694,10 @@ dcrypt_openssl_ctx_hmac_init(struct dcrypt_context_hmac *ctx,
                return dcrypt_openssl_error(error_r);
 #endif
        ec = HMAC_Init_ex(ctx->ctx, ctx->key, ctx->klen, ctx->md, NULL);
-       if (ec != 1)
+       if (ec != 1) {
+               HMAC_CTX_free(ctx->ctx);
                return dcrypt_openssl_error(error_r);
+       }
        return TRUE;
 }
 
index 534472d96f1da4edae295d363b284a3b78705833..fc783e27d0bf316e1589784bfff66c2626f3b866 100644 (file)
@@ -632,8 +632,10 @@ dcrypt_openssl_ctx_hmac_init(struct dcrypt_context_hmac *ctx,
        if (ctx->ctx == NULL)
                return dcrypt_openssl_error(error_r);
        ec = EVP_MAC_init(ctx->ctx, ctx->key, ctx->klen, params);
-       if (ec != 1)
+       if (ec != 1) {
+               EVP_MAC_CTX_free(ctx->ctx);
                return dcrypt_openssl_error(error_r);
+       }
        return TRUE;
 }