-
Notifications
You must be signed in to change notification settings - Fork 7.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Large values for openssl_csr_sign() $days overflow #16433
Comments
Line 3352 in 39533af
Casting an arbitrary ext/openssl/openssl.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/ext/openssl/openssl.c b/ext/openssl/openssl.c
index a4b841dca8..f6994a06c5 100644
--- a/ext/openssl/openssl.c
+++ b/ext/openssl/openssl.c
@@ -3281,6 +3281,11 @@ PHP_FUNCTION(openssl_csr_sign)
goto cleanup;
}
+ if (num_days < 0 || num_days > LONG_MAX / 86400) {
+ php_error_docref(NULL, E_WARNING, "Days must be between 0 and %ld", LONG_MAX / 86400);
+ goto cleanup;
+ }
+
if (PHP_SSL_REQ_PARSE(&req, args) == FAILURE) {
goto cleanup;
}
@@ -3349,7 +3354,7 @@ PHP_FUNCTION(openssl_csr_sign)
goto cleanup;
}
X509_gmtime_adj(X509_getm_notBefore(new_cert), 0);
- X509_gmtime_adj(X509_getm_notAfter(new_cert), 60*60*24*(long)num_days);
+ X509_gmtime_adj(X509_getm_notAfter(new_cert), 60*60*24*num_days);
i = X509_set_pubkey(new_cert, key);
if (!i) {
php_openssl_store_errors(); Note that |
The `offset_sec` parameter of `X509_gmtime_adj()` expects a `long`, but the `$days` parameter of `openssl_csr_sign()` a `zend_long`. We must avoid signed integer overflow (UB), but also must not silently truncate. Thus we check the given `$days` for the permissible range, and bail out otherwise.
* PHP-8.2: Fix GH-16433: Large values for openssl_csr_sign() $days overflow
* PHP-8.3: Fix GH-16433: Large values for openssl_csr_sign() $days overflow
* PHP-8.4: Fix GH-16433: Large values for openssl_csr_sign() $days overflow
Description
The following code:
Resulted in this output:
PHP Version
nightly
Operating System
ubuntu 22.04
The text was updated successfully, but these errors were encountered: