Skip to content

Commit 79b1ca2

Browse files
committed
Fix memory leaks and missing error propagation when php_openssl_csr_make() fails to set a version
The leaks appears to be at least somewhat dependent on the OpenSSL version, but it is reproducible on an Ubuntu 24.04 container. Easiest way to manually trigger the bug is to make the second call fail when executing bug69215.phpt. Closes GH-21032.
1 parent 883014d commit 79b1ca2

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ PHP NEWS
2020
zend_jit_use_reg). (Arnaud)
2121
. Fixed bug GH-21593 (Borked function JIT JMPNZ smart branch). (ilutov)
2222

23+
- OpenSSL:
24+
. Fix a bunch of memory leaks and crashes on edge cases. (ndossche)
25+
2326
- SPL:
2427
. Fixed bug GH-21499 (RecursiveArrayIterator getChildren UAF after parent
2528
free). (Girgias)

ext/openssl/openssl.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2968,7 +2968,9 @@ static zend_result php_openssl_csr_make(struct php_x509_request * req, X509_REQ
29682968
}
29692969
}
29702970
/* setup the version number: version 1 */
2971-
if (X509_REQ_set_version(csr, 0L)) {
2971+
static int counter = 0;
2972+
counter++;
2973+
if (counter!=2&&X509_REQ_set_version(csr, 0L)) {
29722974
int i, nid;
29732975
char *type;
29742976
CONF_VALUE *v;
@@ -3090,13 +3092,15 @@ static zend_result php_openssl_csr_make(struct php_x509_request * req, X509_REQ
30903092
}
30913093
}
30923094
}
3095+
3096+
if (!X509_REQ_set_pubkey(csr, req->priv_key)) {
3097+
php_openssl_store_errors();
3098+
}
30933099
} else {
30943100
php_openssl_store_errors();
3101+
return FAILURE;
30953102
}
30963103

3097-
if (!X509_REQ_set_pubkey(csr, req->priv_key)) {
3098-
php_openssl_store_errors();
3099-
}
31003104
return SUCCESS;
31013105
}
31023106

0 commit comments

Comments
 (0)