Skip to content

Commit

Permalink
Merge branch 'PHP-8.2' into PHP-8.3
Browse files Browse the repository at this point in the history
* PHP-8.2:
  Fix various memory leaks on error conditions in openssl_x509_parse()
  • Loading branch information
nielsdos committed Nov 4, 2024
2 parents dca438e + 5ddb756 commit 673e8d1
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
2 changes: 2 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ PHP NEWS
(cmb)
. Fixed bug GH-16433 (Large values for openssl_csr_sign() $days overflow).
(cmb)
. Fix various memory leaks on error conditions in openssl_x509_parse().
(nielsdos)

- PDO_ODBC:
. Fixed bug GH-16450 (PDO_ODBC can inject garbage into field values). (cmb)
Expand Down
22 changes: 14 additions & 8 deletions ext/openssl/openssl.c
Original file line number Diff line number Diff line change
Expand Up @@ -2131,15 +2131,15 @@ PHP_FUNCTION(openssl_x509_parse)
/* Can return NULL on error or memory allocation failure */
if (!bn_serial) {
php_openssl_store_errors();
RETURN_FALSE;
goto err;
}

hex_serial = BN_bn2hex(bn_serial);
BN_free(bn_serial);
/* Can return NULL on error or memory allocation failure */
if (!hex_serial) {
php_openssl_store_errors();
RETURN_FALSE;
goto err;
}

str_serial = i2s_ASN1_INTEGER(NULL, asn1_serial);
Expand Down Expand Up @@ -2211,19 +2211,15 @@ PHP_FUNCTION(openssl_x509_parse)
bio_out = BIO_new(BIO_s_mem());
if (bio_out == NULL) {
php_openssl_store_errors();
RETURN_FALSE;
goto err_subitem;
}
if (nid == NID_subject_alt_name) {
if (openssl_x509v3_subjectAltName(bio_out, extension) == 0) {
BIO_get_mem_ptr(bio_out, &bio_buf);
add_assoc_stringl(&subitem, extname, bio_buf->data, bio_buf->length);
} else {
zend_array_destroy(Z_ARR_P(return_value));
BIO_free(bio_out);
if (cert_str) {
X509_free(cert);
}
RETURN_FALSE;
goto err_subitem;
}
}
else if (X509V3_EXT_print(bio_out, extension, 0, 0)) {
Expand All @@ -2238,6 +2234,16 @@ PHP_FUNCTION(openssl_x509_parse)
if (cert_str) {
X509_free(cert);
}
return;

err_subitem:
zval_ptr_dtor(&subitem);
err:
zend_array_destroy(Z_ARR_P(return_value));
if (cert_str) {
X509_free(cert);
}
RETURN_FALSE;
}
/* }}} */

Expand Down

0 comments on commit 673e8d1

Please sign in to comment.