Fixing memory leak in openssl_pkcs12_read when zout initialisation fails#3
Open
JarneClauw wants to merge 2 commits intoPHP-8.4from
Open
Fixing memory leak in openssl_pkcs12_read when zout initialisation fails#3JarneClauw wants to merge 2 commits intoPHP-8.4from
JarneClauw wants to merge 2 commits intoPHP-8.4from
Conversation
ndossche
suggested changes
Apr 14, 2026
There was a problem hiding this comment.
Dit is vrij ingewikkeld, en er ontbreekt een test.
Een simpele test zou dit kunnen zijn:
--TEST--
Memory leak when array initialization in openssl_pkcs12_read() fails
--EXTENSIONS--
openssl
--FILE--
<?php
$pfx = __DIR__ . DIRECTORY_SEPARATOR . "bug74022.pfx";
$cert_store = file_get_contents($pfx);
class Typed {
public string $foo = "bar";
}
$typed = new Typed;
try {
openssl_pkcs12_read($cert_store, $typed->foo, "csos");
} catch (TypeError $e) {
echo $e::class, ": ", $e->getMessage(), "\n";
}
?>
--EXPECT--
TypeError: Cannot assign array to reference held by property Typed::$foo of type stringWaarschijnlijk is het simpeler om een one-line fix te doen in het codeblock direct na de gefaalde check; en sk_X509_pop_free te gebruiken?
ndossche
approved these changes
Apr 14, 2026
ndossche
left a comment
There was a problem hiding this comment.
Het enige dat ik niet zeker ben is of dit ook werkt op LibreSSL. Het zou kunnen dat sk_X509_pop_free daar niet bestaat. In dat geval zal er wss ergens een helper zijn in de PHP code of zal er een lelijker alternatief zijn. Maar je zal wel zien wat de PHP CI zegt en wat de maintainer zegt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Found by a static-dynamic analyzer looking for memory bugs in error-handling paths.