Skip to content

Commit ca1b30a

Browse files
committed
Simplified cleanup and adding test
1 parent a364224 commit ca1b30a

2 files changed

Lines changed: 24 additions & 10 deletions

File tree

ext/openssl/openssl.c

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2847,6 +2847,7 @@ PHP_FUNCTION(openssl_pkcs12_read)
28472847

28482848
zout = zend_try_array_init(zout);
28492849
if (!zout) {
2850+
sk_X509_pop_free(ca, X509_free);
28502851
goto cleanup;
28512852
}
28522853

@@ -2898,7 +2899,6 @@ PHP_FUNCTION(openssl_pkcs12_read)
28982899
}
28992900

29002901
sk_X509_free(ca);
2901-
ca = NULL;
29022902
add_assoc_zval(zout, "extracerts", &zextracerts);
29032903
}
29042904

@@ -2916,15 +2916,6 @@ PHP_FUNCTION(openssl_pkcs12_read)
29162916
if (p12) {
29172917
PKCS12_free(p12);
29182918
}
2919-
int cert_num = sk_X509_num(ca);
2920-
if (ca && cert_num) {
2921-
for (i = 0; i < cert_num; i++) {
2922-
X509* aCA = sk_X509_pop(ca);
2923-
if (!aCA) break;
2924-
X509_free(aCA);
2925-
}
2926-
sk_X509_free(ca);
2927-
}
29282919
}
29292920
/* }}} */
29302921

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)