[php-src] PR #21801: phar: free EVP_PKEY on EVP_MD_CTX_create/EVP_VerifyInit failure in phar_verify_signature
| From: | iliaal | Date: | Sat, 18 Apr 2026 13:13:24 +0000 |
| Subject: | [php-src] PR #21801: phar: free EVP_PKEY on EVP_MD_CTX_create/EVP_VerifyInit failure in phar_verify_signature | ||
| Groups: | php.git-pulls | ||
| Request: | Send a blank email to git-pulls+get-35772@lists.php.net to get a copy of this message | ||
Pull Request: https://github.com/php/php-src/pull/21801
Author: iliaal
In
phar_verify_signature, PEM_read_bio_PUBKEY allocates EVP_PKEY
*key. When EVP_MD_CTX_create() returns NULL or EVP_VerifyInit()
fails, the early return freed md_ctx but did not call EVP_PKEY_free(key),
leaking the object in OpenSSL's heap.
The existing failure: label (reached on bad signature or EVP_VerifyUpdate
errors) already calls both EVP_PKEY_free and EVP_MD_CTX_destroy. The fix
adds EVP_PKEY_free(key) to the earlier exit branch, mirroring the symmetric fix in
phar_create_signature from GH-19563 (f5a3a642c61).
ASAN catches the leak when EVP_VerifyInit fails, in FIPS-mode deployments with SHA-1
disabled.