8000 Improve error reporting in random extension by TimWolla · Pull Request #9071 · php/php-src · GitHub
[go: up one dir, main page]

Skip to content

Improve error reporting in random extension #9071

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Jul 25, 2022
Prev Previous commit
Next Next commit
Improve user_unsafe test
Select parameters for ->getInt() that will actually lead to unsafe behavior.
  • Loading branch information
TimWolla committed Jul 20, 2022
commit 12b07ced2e006365aba1fa575d7b9261a925d42a
28 changes: 17 additions & 11 deletions ext/random/tests/03_randomizer/user_unsafe.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ $randomizer = (new \Random\Randomizer(
));

try {
var_dump($randomizer->getInt(\PHP_INT_MIN, \PHP_INT_MAX));
var_dump($randomizer->getInt(0, 123));
} catch (\RuntimeException $e) {
echo $e, PHP_EOL;
}
Expand Down Expand Up @@ -56,7 +56,7 @@ $randomizer = (new \Random\Randomizer(
));

try {
var_dump($randomizer->getInt(\PHP_INT_MIN, \PHP_INT_MAX));
var_dump($randomizer->getInt(0, 123));
} catch (\RuntimeException $e) {
echo $e, PHP_EOL;
}
Expand Down Expand Up @@ -89,12 +89,12 @@ try {
--EXPECTF--
DomainException: A random engine must return a non-empty string in %s:%d
Stack trace:
#0 %s(%d): Random\Randomizer->getInt(%d, %d)
#0 %s(%d): Random\Randomizer->getInt(0, 123)
#1 {main}

Next RuntimeException: Random number generation failed in %s:%d
Stack trace:
#0 %s(%d): Random\Randomizer->getInt(%d, %d)
#0 %s(%d): Random\Randomizer->getInt(0, 123)
#1 {main}

-------
Expand Down Expand Up @@ -135,20 +135,26 @@ Stack trace:

=======

int(%d)

-------
RuntimeException: Failed to generate an acceptable random number in 50 attempts in %s:%d
Stack trace:
#0 %s(%d): Random\Randomizer->getInt(0, 123)
#1 {main}

string(2) "ff"
Next RuntimeException: Random number generation failed in %s:%d
Stack trace:
#0 %s(%d): Random\Randomizer->getInt(0, 123)
#1 {main}

-------

RuntimeException: Failed to generate an acceptable random number in 50 attempts in %s:%d
RuntimeException: Random number generation failed in %s:%d
Stack trace:
#0 %s(%d): Random\Randomizer->shuffleArray(Array)
#0 %s(%d): Random\Randomizer->getBytes(1)
#1 {main}

Next RuntimeException: Random number generation failed in %s:%d
-------

RuntimeException: Random number generation failed in %s:%d
Stack trace:
#0 %s(%d): Random\Randomizer->shuffleArray(Array)
#1 {main}
Expand Down
0