Skip to content

Commit ef1c3b8

Browse files
committed
Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3: Fix GH-16433: Large values for openssl_csr_sign() $days overflow
2 parents 9a4ec40 + 931762c commit ef1c3b8

File tree

3 files changed

+25
-1
lines changed

3 files changed

+25
-1
lines changed

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ PHP NEWS
5656
- OpenSSL:
5757
. Fixed bug GH-16357 (openssl may modify member types of certificate arrays).
5858
(cmb)
59+
. Fixed bug GH-16433 (Large values for openssl_csr_sign() $days overflow).
60+
(cmb)
5961

6062
- PHPDBG:
6163
. Fixed bug GH-16174 (Empty string is an invalid expression for ev). (cmb)

ext/openssl/openssl.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3281,6 +3281,11 @@ PHP_FUNCTION(openssl_csr_sign)
32813281
goto cleanup;
32823282
}
32833283

3284+
if (num_days < 0 || num_days > LONG_MAX / 86400) {
3285+
php_error_docref(NULL, E_WARNING, "Days must be between 0 and %ld", LONG_MAX / 86400);
3286+
goto cleanup;
3287+
}
3288+
32843289
if (PHP_SSL_REQ_PARSE(&req, args) == FAILURE) {
32853290
goto cleanup;
32863291
}
@@ -3349,7 +3354,7 @@ PHP_FUNCTION(openssl_csr_sign)
33493354
goto cleanup;
33503355
}
33513356
X509_gmtime_adj(X509_getm_notBefore(new_cert), 0);
3352-
X509_gmtime_adj(X509_getm_notAfter(new_cert), 60*60*24*(long)num_days);
3357+
X509_gmtime_adj(X509_getm_notAfter(new_cert), 60*60*24*num_days);
33533358
i = X509_set_pubkey(new_cert, key);
33543359
if (!i) {
33553360
php_openssl_store_errors();

ext/openssl/tests/gh16433.phpt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
--TEST--
2+
GH-16433 (Large values for openssl_csr_sign() $days overflow)
3+
--EXTENSIONS--
4+
openssl
5+
--FILE--
6+
<?php
7+
$privkey = openssl_pkey_new();
8+
$csr = openssl_csr_new([], $privkey);
9+
var_dump(openssl_csr_sign($csr, null, $privkey, PHP_INT_MAX));
10+
var_dump(openssl_csr_sign($csr, null, $privkey, -1));
11+
?>
12+
--EXPECTF--
13+
Warning: openssl_csr_sign(): Days must be between 0 and %d in %s on line %d
14+
bool(false)
15+
16+
Warning: openssl_csr_sign(): Days must be between 0 and %d in %s on line %d
17+
bool(false)

0 commit comments

Comments
 (0)