Skip to content

Commit ebaaa7d

Browse files
committed
Merge branch 'PHP-8.4' into PHP-8.5
* PHP-8.4: Fix memory leaks when php_openssl_dh_pub_from_priv() fails openssl: Propagate PHP_OPENSSL_ASN1_INTEGER_set() failure
2 parents 0f2b93e + 35e8cb8 commit ebaaa7d

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
@@ -1797,7 +1797,11 @@ PHP_FUNCTION(openssl_csr_sign)
17971797
goto cleanup;
17981798
}
17991799
} else {
1800-
PHP_OPENSSL_ASN1_INTEGER_set(X509_get_serialNumber(new_cert), serial);
1800+
if (!PHP_OPENSSL_ASN1_INTEGER_set(X509_get_serialNumber(new_cert), serial)) {
1801+
php_openssl_store_errors();
1802+
php_error_docref(NULL, E_WARNING, "Error setting serial number");
1803+
goto cleanup;
1804+
}
18011805
}
18021806

18031807
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 0;
207+
}
208+
209+
if (!DH_set0_pqg(dh, p, q, g)) {
205210
return 0;
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 0;
218227
}
219228
return DH_set0_key(dh, pub_key, priv_key);

0 commit comments

Comments
 (0)