Skip to content

Commit 931762c

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

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
@@ -52,6 +52,8 @@ PHP NEWS
5252
- OpenSSL:
5353
. Fixed bug GH-16357 (openssl may modify member types of certificate arrays).
5454
(cmb)
55+
. Fixed bug GH-16433 (Large values for openssl_csr_sign() $days overflow).
56+
(cmb)
5557

5658
- PHPDBG:
5759
. 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
@@ -3240,6 +3240,11 @@ PHP_FUNCTION(openssl_csr_sign)
32403240
goto cleanup;
32413241
}
32423242

3243+
if (num_days < 0 || num_days > LONG_MAX / 86400) {
3244+
php_error_docref(NULL, E_WARNING, "Days must be between 0 and %ld", LONG_MAX / 86400);
3245+
goto cleanup;
3246+
}
3247+
32433248
if (PHP_SSL_REQ_PARSE(&req, args) == FAILURE) {
32443249
goto cleanup;
32453250
}
@@ -3291,7 +3296,7 @@ PHP_FUNCTION(openssl_csr_sign)
32913296
goto cleanup;
32923297
}
32933298
X509_gmtime_adj(X509_getm_notBefore(new_cert), 0);
3294-
X509_gmtime_adj(X509_getm_notAfter(new_cert), 60*60*24*(long)num_days);
3299+
X509_gmtime_adj(X509_getm_notAfter(new_cert), 60*60*24*num_days);
32953300
i = X509_set_pubkey(new_cert, key);
32963301
if (!i) {
32973302
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)