Skip to content

Commit 2f404e7

Browse files
authored
Fix ZEND_LONG_UINT_OVFL() accepting negative values on 32-bit platforms (#24778)
Where zend_long is not wider than an int, ZEND_LONG_UINT_OVFL() was defined as 0, so a negative value passed the check there, while it is rejected where zend_long is wider. Keep checking the lower bound on these platforms too. This affects mbstring.regex_stack_limit, mbstring.regex_retry_limit and the codepage of sapi_windows_cp_set() and sapi_windows_cp_conv().
1 parent 2c4fdd7 commit 2f404e7

4 files changed

Lines changed: 67 additions & 1 deletion

File tree

‎NEWS‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,8 @@ PHP NEWS
139139
. Fixed bug GH-23958 (truncated encoding names resolving to full names). (Kamil Tekiela)
140140
. Fixed out-of-bounds read in php_mb_rfc1867_getword() on a multibyte lead
141141
byte at the end of a multipart field name. (Jorg Sowa)
142+
. Fixed negative mbstring.regex_stack_limit and mbstring.regex_retry_limit
143+
on 32bit platforms. (Marc Bennewitz)
142144

143145
- MySQLnd:
144146
. Fixed bug GH-24293 (Segfault on connect with an empty password to a
@@ -333,6 +335,8 @@ PHP NEWS
333335
tidy::repairFile() rejecting null for $encoding. (lacatoire)
334336

335337
- Windows:
338+
. Fixed sapi_windows_cp_set() and sapi_windows_cp_conv() accepting a negative
339+
codepage on 32bit platforms. (Marc Bennewitz)
336340
. Fixed bug GH-25009 (GetConsoleTitleW() buffer size passed in bytes).
337341
(Lazizbek Ergashev)
338342

‎Zend/zend_range_check.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
# define ZEND_LONG_INT_OVFL(zl) (0)
4848
# define ZEND_LONG_INT_UDFL(zl) (0)
4949
# define ZEND_LONG_EXCEEDS_INT(zlong) (0)
50-
# define ZEND_LONG_UINT_OVFL(zl) (0)
50+
# define ZEND_LONG_UINT_OVFL(zl) UNEXPECTED((zl) < 0)
5151
#endif
5252

5353
/* size_t vs (unsigned) int checks. */
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
--TEST--
2+
Oniguruma retry limit is not set from a negative mbstring.regex_retry_limit
3+
--EXTENSIONS--
4+
mbstring
5+
--SKIPIF--
6+
<?php
7+
if (!function_exists('mb_ereg')) die('skip mb_ereg not available');
8+
if (@version_compare(MB_ONIGURUMA_VERSION, '6.9.3') < 0) {
9+
die('skip requires Oniguruma >= 6.9.3');
10+
}
11+
?>
12+
--INI--
13+
error_reporting=E_ALL & ~E_DEPRECATED
14+
mbstring.regex_retry_limit=-1
15+
--FILE--
16+
<?php
17+
/* A negative limit must leave the default of Oniguruma in place, rather than
18+
* being converted to an unsigned int of UINT_MAX. This match needs more
19+
* retries than the default allows for. */
20+
$regex = 'A(B|C+)+D|AC+X';
21+
$str = 'A' . str_repeat('C', 24) . 'X';
22+
var_dump(mb_ereg($regex, $str));
23+
?>
24+
--EXPECT--
25+
bool(false)
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
--TEST--
2+
sapi_windows_cp_set() and sapi_windows_cp_conv() must reject a negative codepage
3+
--SKIPIF--
4+
<?php
5+
if (PHP_OS_FAMILY !== 'Windows') die('skip for Windows only');
6+
?>
7+
--FILE--
8+
<?php
9+
try {
10+
sapi_windows_cp_set(-1);
11+
} catch (Throwable $e) {
12+
echo $e::class, ': ', $e->getMessage(), "\n";
13+
}
14+
15+
try {
16+
sapi_windows_cp_set(PHP_INT_MIN);
17+
} catch (Throwable $e) {
18+
echo $e::class, ': ', $e->getMessage(), "\n";
19+
}
20+
21+
try {
22+
sapi_windows_cp_conv(-1, 65001, 'php');
23+
} catch (Throwable $e) {
24+
echo $e::class, ': ', $e->getMessage(), "\n";
25+
}
26+
27+
try {
28+
sapi_windows_cp_conv(65001, -1, 'php');
29+
} catch (Throwable $e) {
30+
echo $e::class, ': ', $e->getMessage(), "\n";
31+
}
32+
?>
33+
--EXPECT--
34+
ValueError: sapi_windows_cp_set(): Argument #1 ($codepage) must be between 0 and 4294967295
35+
ValueError: sapi_windows_cp_set(): Argument #1 ($codepage) must be between 0 and 4294967295
36+
ValueError: sapi_windows_cp_conv(): Argument #1 ($in_codepage) must be between 0 and 4294967295
37+
ValueError: sapi_windows_cp_conv(): Argument #2 ($out_codepage) must be between 0 and 4294967295

0 commit comments

Comments
 (0)