Skip to content

Commit 673e8d1

Browse files
committed
Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2: Fix various memory leaks on error conditions in openssl_x509_parse()
2 parents dca438e + 5ddb756 commit 673e8d1

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,8 @@ PHP NEWS
9292
(cmb)
9393
. Fixed bug GH-16433 (Large values for openssl_csr_sign() $days overflow).
9494
(cmb)
95+
. Fix various memory leaks on error conditions in openssl_x509_parse().
96+
(nielsdos)
9597

9698
- PDO_ODBC:
9799
. Fixed bug GH-16450 (PDO_ODBC can inject garbage into field values). (cmb)

ext/openssl/openssl.c

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2131,15 +2131,15 @@ PHP_FUNCTION(openssl_x509_parse)
21312131
/* Can return NULL on error or memory allocation failure */
21322132
if (!bn_serial) {
21332133
php_openssl_store_errors();
2134-
RETURN_FALSE;
2134+
goto err;
21352135
}
21362136

21372137
hex_serial = BN_bn2hex(bn_serial);
21382138
BN_free(bn_serial);
21392139
/* Can return NULL on error or memory allocation failure */
21402140
if (!hex_serial) {
21412141
php_openssl_store_errors();
2142-
RETURN_FALSE;
2142+
goto err;
21432143
}
21442144

21452145
str_serial = i2s_ASN1_INTEGER(NULL, asn1_serial);
@@ -2211,19 +2211,15 @@ PHP_FUNCTION(openssl_x509_parse)
22112211
bio_out = BIO_new(BIO_s_mem());
22122212
if (bio_out == NULL) {
22132213
php_openssl_store_errors();
2214-
RETURN_FALSE;
2214+
goto err_subitem;
22152215
}
22162216
if (nid == NID_subject_alt_name) {
22172217
if (openssl_x509v3_subjectAltName(bio_out, extension) == 0) {
22182218
BIO_get_mem_ptr(bio_out, &bio_buf);
22192219
add_assoc_stringl(&subitem, extname, bio_buf->data, bio_buf->length);
22202220
} else {
2221-
zend_array_destroy(Z_ARR_P(return_value));
22222221
BIO_free(bio_out);
2223-
if (cert_str) {
2224-
X509_free(cert);
2225-
}
2226-
RETURN_FALSE;
2222+
goto err_subitem;
22272223
}
22282224
}
22292225
else if (X509V3_EXT_print(bio_out, extension, 0, 0)) {
@@ -2238,6 +2234,16 @@ PHP_FUNCTION(openssl_x509_parse)
22382234
if (cert_str) {
22392235
X509_free(cert);
22402236
}
2237+
return;
2238+
2239+
err_subitem:
2240+
zval_ptr_dtor(&subitem);
2241+
err:
2242+
zend_array_destroy(Z_ARR_P(return_value));
2243+
if (cert_str) {
2244+
X509_free(cert);
2245+
}
2246+
RETURN_FALSE;
22412247
}
22422248
/* }}} */
22432249

0 commit comments

Comments
 (0)