Skip to content

Fix GH-16433: Large values for openssl_csr_sign() $days overflow #16437

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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion ext/openssl/openssl.c
Original file line number Diff line number Diff line change
Expand Up @@ -3200,6 +3200,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;
}
Expand Down Expand Up @@ -3251,7 +3256,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();
Expand Down
17 changes: 17 additions & 0 deletions ext/openssl/tests/gh16433.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
--TEST--
GH-16433 (Large values for openssl_csr_sign() $days overflow)
--EXTENSIONS--
openssl
--FILE--
<?php
$privkey = openssl_pkey_new();
$csr = openssl_csr_new([], $privkey);
var_dump(openssl_csr_sign($csr, null, $privkey, PHP_INT_MAX));
var_dump(openssl_csr_sign($csr, null, $privkey, -1));
?>
--EXPECTF--
Warning: openssl_csr_sign(): Days must be between 0 and %d in %s on line %d
bool(false)

Warning: openssl_csr_sign(): Days must be between 0 and %d in %s on line %d
bool(false)
Loading