Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Simplified cleanup and adding test
  • Loading branch information
JarneClauw committed Apr 14, 2026
commit ca1b30a453613a70fa940ff6fcd0400ce0ee66cd
11 changes: 1 addition & 10 deletions ext/openssl/openssl.c
Original file line number Diff line number Diff line change
Expand Up @@ -2847,6 +2847,7 @@ PHP_FUNCTION(openssl_pkcs12_read)

zout = zend_try_array_init(zout);
if (!zout) {
sk_X509_pop_free(ca, X509_free);
goto cleanup;
}

Expand Down Expand Up @@ -2898,7 +2899,6 @@ PHP_FUNCTION(openssl_pkcs12_read)
}

sk_X509_free(ca);
ca = NULL;
add_assoc_zval(zout, "extracerts", &zextracerts);
}

Expand All @@ -2916,15 +2916,6 @@ PHP_FUNCTION(openssl_pkcs12_read)
if (p12) {
PKCS12_free(p12);
}
int cert_num = sk_X509_num(ca);
if (ca && cert_num) {
for (i = 0; i < cert_num; i++) {
X509* aCA = sk_X509_pop(ca);
if (!aCA) break;
X509_free(aCA);
}
sk_X509_free(ca);
}
}
/* }}} */

Expand Down
23 changes: 23 additions & 0 deletions ext/openssl/tests/openssl_pkcs12_read_array_init.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
--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 string
Loading