Skip to content

Commit 1fa8c0f

Browse files
committed
Merge branch 'PHP-8.5'
* PHP-8.5: Fix memory leaks when php_openssl_dh_pub_from_priv() fails openssl: Propagate PHP_OPENSSL_ASN1_INTEGER_set() failure
2 parents b7c855f + ebaaa7d commit 1fa8c0f

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

ext/openssl/openssl.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1815,7 +1815,11 @@ PHP_FUNCTION(openssl_csr_sign)
18151815
goto cleanup;
18161816
}
18171817
} else {
1818-
PHP_OPENSSL_ASN1_INTEGER_set(X509_get_serialNumber(new_cert), serial);
1818+
if (!PHP_OPENSSL_ASN1_INTEGER_set(X509_get_serialNumber(new_cert), serial)) {
1819+
php_openssl_store_errors();
1820+
php_error_docref(NULL, E_WARNING, "Error setting serial number");
1821+
goto cleanup;
1822+
}
18191823
}
18201824

18211825
if (!X509_set_subject_name(new_cert, X509_REQ_get_subject_name(csr))) {

ext/openssl/openssl_backend_v1.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,12 @@ static bool php_openssl_pkey_init_dh_data(DH *dh, zval *data, bool *is_private)
201201
OPENSSL_PKEY_SET_BN(data, p);
202202
OPENSSL_PKEY_SET_BN(data, q);
203203
OPENSSL_PKEY_SET_BN(data, g);
204-
if (!p || !g || !DH_set0_pqg(dh, p, q, g)) {
204+
if (!p || !q) {
205+
BN_free(p);
206+
return false;
207+
}
208+
209+
if (!DH_set0_pqg(dh, p, q, g)) {
205210
return false;
206211
}
207212

@@ -214,6 +219,10 @@ static bool php_openssl_pkey_init_dh_data(DH *dh, zval *data, bool *is_private)
214219
if (priv_key) {
215220
pub_key = php_openssl_dh_pub_from_priv(priv_key, g, p);
216221
if (pub_key == NULL) {
222+
BN_free(p);
223+
BN_free(q);
224+
BN_free(g);
225+
BN_free(priv_key);
217226
return false;
218227
}
219228
return DH_set0_key(dh, pub_key, priv_key);

0 commit comments

Comments
 (0)