Skip to content

Commit 8204d4b

Browse files
authored
Fixing memory leak in openssl_pkcs12_read when zout initialisation fails (#21752)
* Fixing memory leak * Simplified cleanup and adding test
1 parent 42c392c commit 8204d4b

2 files changed

Lines changed: 24 additions & 0 deletions

File tree

‎ext/openssl/openssl.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2859,6 +2859,7 @@ PHP_FUNCTION(openssl_pkcs12_read)
28592859

28602860
zout = zend_try_array_init(zout);
28612861
if (!zout) {
2862+
sk_X509_pop_free(ca, X509_free);
28622863
goto cleanup;
28632864
}
28642865

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
--TEST--
2+
Memory leak when array initialization in openssl_pkcs12_read() fails
3+
--EXTENSIONS--
4+
openssl
5+
--FILE--
6+
<?php
7+
$pfx = __DIR__ . DIRECTORY_SEPARATOR . "bug74022.pfx";
8+
$cert_store = file_get_contents($pfx);
9+
10+
class Typed {
11+
public string $foo = "bar";
12+
}
13+
14+
$typed = new Typed;
15+
16+
try {
17+
openssl_pkcs12_read($cert_store, $typed->foo, "csos");
18+
} catch (TypeError $e) {
19+
echo $e::class, ": ", $e->getMessage(), "\n";
20+
}
21+
?>
22+
--EXPECT--
23+
TypeError: Cannot assign array to reference held by property Typed::$foo of type string

0 commit comments

Comments
 (0)