Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions ext/random/random.c
Original file line number Diff line number Diff line change
Expand Up @@ -574,8 +574,8 @@ PHP_FUNCTION(random_bytes)
Z_PARAM_LONG(size)
ZEND_PARSE_PARAMETERS_END();

if (size < 1) {
zend_argument_value_error(1, "must be greater than 0");
if (size < 0) {
zend_argument_value_error(1, "must be greater than or equal to 0");
RETURN_THROWS();
}

Expand Down
7 changes: 4 additions & 3 deletions ext/random/tests/01_functions/random_bytes_error.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,21 @@ Test error operation of random_bytes()
--FILE--
<?php
//-=-=-=-

var_dump(random_bytes(0));
try {
$bytes = random_bytes();
} catch (TypeError $e) {
echo $e->getMessage().PHP_EOL;
}

try {
$bytes = random_bytes(0);
$bytes = random_bytes(-1);
} catch (Error $e) {
echo $e->getMessage().PHP_EOL;
}

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