Skip to content

Commit faef0df

Browse files
committed
Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3: Fix various memory leaks on error conditions in openssl_x509_parse()
2 parents 66ad4ce + 673e8d1 commit faef0df

File tree

2 files changed

+18
-8
lines changed

2 files changed

+18
-8
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ PHP NEWS
3535
. Fixed bug GH-16572 (Incorrect result with reflection in low-trigger JIT).
3636
(nielsdos)
3737

38+
- OpenSSL:
39+
. Fix various memory leaks on error conditions in openssl_x509_parse().
40+
(nielsdos)
41+
3842
- PDO:
3943
. Fixed bug GH-16167 (Prevent mixing PDO sub-classes with different DSN).
4044
(kocsismate)

ext/openssl/openssl.c

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2153,15 +2153,15 @@ PHP_FUNCTION(openssl_x509_parse)
21532153
/* Can return NULL on error or memory allocation failure */
21542154
if (!bn_serial) {
21552155
php_openssl_store_errors();
2156-
RETURN_FALSE;
2156+
goto err;
21572157
}
21582158

21592159
hex_serial = BN_bn2hex(bn_serial);
21602160
BN_free(bn_serial);
21612161
/* Can return NULL on error or memory allocation failure */
21622162
if (!hex_serial) {
21632163
php_openssl_store_errors();
2164-
RETURN_FALSE;
2164+
goto err;
21652165
}
21662166

21672167
str_serial = i2s_ASN1_INTEGER(NULL, asn1_serial);
@@ -2233,19 +2233,15 @@ PHP_FUNCTION(openssl_x509_parse)
22332233
bio_out = BIO_new(BIO_s_mem());
22342234
if (bio_out == NULL) {
22352235
php_openssl_store_errors();
2236-
RETURN_FALSE;
2236+
goto err_subitem;
22372237
}
22382238
if (nid == NID_subject_alt_name) {
22392239
if (openssl_x509v3_subjectAltName(bio_out, extension) == 0) {
22402240
BIO_get_mem_ptr(bio_out, &bio_buf);
22412241
add_assoc_stringl(&subitem, extname, bio_buf->data, bio_buf->length);
22422242
} else {
2243-
zend_array_destroy(Z_ARR_P(return_value));
22442243
BIO_free(bio_out);
2245-
if (cert_str) {
2246-
X509_free(cert);
2247-
}
2248-
RETURN_FALSE;
2244+
goto err_subitem;
22492245
}
22502246
}
22512247
else if (X509V3_EXT_print(bio_out, extension, 0, 0)) {
@@ -2260,6 +2256,16 @@ PHP_FUNCTION(openssl_x509_parse)
22602256
if (cert_str) {
22612257
X509_free(cert);
22622258
}
2259+
return;
2260+
2261+
err_subitem:
2262+
zval_ptr_dtor(&subitem);
2263+
err:
2264+
zend_array_destroy(Z_ARR_P(return_value));
2265+
if (cert_str) {
2266+
X509_free(cert);
2267+
}
2268+
RETURN_FALSE;
22632269
}
22642270
/* }}} */
22652271

0 commit comments

Comments
 (0)