]> git.ipfire.org Git - thirdparty/hostap.git/commitdiff
OpenSSL: Fix a memory leak in crypto_ec_key_parse_priv()
authorJouni Malinen <j@w1.fi>
Sun, 21 Jan 2024 22:37:31 +0000 (00:37 +0200)
committerJouni Malinen <j@w1.fi>
Sun, 21 Jan 2024 22:37:31 +0000 (00:37 +0200)
The OpenSSL 3.x version of crypto_ec_key_parse_priv using
OSSL_DECODER_CTX missed the call to free the context. Fix it to avoid a
memory leak.

Fixes: 4f4479ef9e1c ("OpenSSL: crypto_ec_key_parse_{priv,pub}() without EC_KEY API")
Signed-off-by: Jouni Malinen <j@w1.fi>
src/crypto/crypto_openssl.c

index 1334f0b7152ed2f83991136c47b8b4120b23dad1..d10949ce7cc19c1519fe61266c2df67bdb68bd2d 100644 (file)
@@ -3010,11 +3010,15 @@ struct crypto_ec_key * crypto_ec_key_parse_priv(const u8 *der, size_t der_len)
                NULL, NULL);
        if (!ctx ||
            OSSL_DECODER_from_data(ctx, &der, &der_len) != 1) {
-               wpa_printf(MSG_INFO, "OpenSSL: Decoding EC private key (DER) failed: %s",
+               wpa_printf(MSG_INFO,
+                          "OpenSSL: Decoding EC private key (DER) failed: %s",
                           ERR_error_string(ERR_get_error(), NULL));
+               if (ctx)
+                       OSSL_DECODER_CTX_free(ctx);
                goto fail;
        }
 
+       OSSL_DECODER_CTX_free(ctx);
        return (struct crypto_ec_key *) pkey;
 fail:
        crypto_ec_key_deinit((struct crypto_ec_key *) pkey);