Skip to content

Commit 1cb7aeb

Browse files
committed
fix random_bytes(0);
1 parent 7aea6dd commit 1cb7aeb

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

ext/random/random.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -574,8 +574,8 @@ PHP_FUNCTION(random_bytes)
574574
Z_PARAM_LONG(size)
575575
ZEND_PARSE_PARAMETERS_END();
576576

577-
if (size < 1) {
578-
zend_argument_value_error(1, "must be greater than 0");
577+
if (size < 0) {
578+
zend_argument_value_error(1, "must be greater than or equal to 0");
579579
RETURN_THROWS();
580580
}
581581

ext/random/tests/01_functions/random_bytes_error.phpt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,21 @@ Test error operation of random_bytes()
33
--FILE--
44
<?php
55
//-=-=-=-
6-
6+
var_dump(random_bytes(0));
77
try {
88
$bytes = random_bytes();
99
} catch (TypeError $e) {
1010
echo $e->getMessage().PHP_EOL;
1111
}
1212

1313
try {
14-
$bytes = random_bytes(0);
14+
$bytes = random_bytes(-1);
1515
} catch (Error $e) {
1616
echo $e->getMessage().PHP_EOL;
1717
}
1818

1919
?>
2020
--EXPECT--
21+
string(0) ""
2122
random_bytes() expects exactly 1 argument, 0 given
22-
random_bytes(): Argument #1 ($length) must be greater than 0
23+
random_bytes(): Argument #1 ($length) must be greater than or equal to 0

0 commit comments

Comments
 (0)