diff --git a/NEWS b/NEWS index 596d4d2bde1..fbe9286c1ca 100644 --- a/NEWS +++ b/NEWS @@ -38,6 +38,10 @@ PHP NEWS - OpenSSL: . Fix memory leaks when sk_X509_new_null() fails. (ndossche) + . Fix crash when in openssl_x509_parse() when i2s_ASN1_INTEGER() fails. + (ndossche) + . Fix crash in openssl_x509_parse() when X509_NAME_oneline() fails. + (ndossche) - Phar: . Fixed bug GH-20882 (buildFromIterator breaks with missing base directory). diff --git a/ext/openssl/openssl.c b/ext/openssl/openssl.c index 2526e5b4429..aa35a2dcbc1 100644 --- a/ext/openssl/openssl.c +++ b/ext/openssl/openssl.c @@ -1030,6 +1030,11 @@ PHP_FUNCTION(openssl_x509_parse) subject_name = X509_get_subject_name(cert); cert_name = X509_NAME_oneline(subject_name, NULL, 0); + if (cert_name == NULL) { + php_openssl_store_errors(); + goto err; + } + add_assoc_string(return_value, "name", cert_name); OPENSSL_free(cert_name); @@ -1062,6 +1067,12 @@ PHP_FUNCTION(openssl_x509_parse) } str_serial = i2s_ASN1_INTEGER(NULL, asn1_serial); + /* Can return NULL on error or memory allocation failure */ + if (!str_serial) { + php_openssl_store_errors(); + goto err; + } + add_assoc_string(return_value, "serialNumber", str_serial); OPENSSL_free(str_serial);