mirror of
https://github.com/php/php-src.git
synced 2024-09-22 02:17:32 +00:00
Use unsigned subtraction in php_random_int()
This subtraction may overflow the signed domain, which is UB. Use an unsigned subtraction instead.
This commit is contained in:
parent
ac356ba81f
commit
265af40a0a
@ -235,7 +235,7 @@ PHPAPI int php_random_int(zend_long min, zend_long max, zend_long *result, zend_
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
umax = max - min;
|
||||
umax = (zend_ulong) max - (zend_ulong) min;
|
||||
|
||||
if (php_random_bytes(&trial, sizeof(trial), should_throw) == FAILURE) {
|
||||
return FAILURE;
|
||||
|
@ -2,7 +2,6 @@
|
||||
Test normal operation of random_int()
|
||||
--FILE--
|
||||
<?php
|
||||
//-=-=-=-
|
||||
|
||||
var_dump(is_int(random_int(10, 100)));
|
||||
|
||||
@ -10,11 +9,15 @@ $x = random_int(10, 100);
|
||||
var_dump($x >= 10 && $x <= 100);
|
||||
|
||||
var_dump(random_int(-1000, -1) < 0);
|
||||
var_dump(random_int(-1, PHP_INT_MAX) >= -1);
|
||||
var_dump(is_int(random_int(PHP_INT_MIN, PHP_INT_MAX)));
|
||||
|
||||
var_dump(random_int(42,42));
|
||||
|
||||
?>
|
||||
--EXPECT--
|
||||
--EXPECTF--
|
||||
bool(true)
|
||||
bool(true)
|
||||
bool(true)
|
||||
bool(true)
|
||||
bool(true)
|
||||
|
Loading…
Reference in New Issue
Block a user