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
8000

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
Use php_random_int_throw() in Secure engine's range()
This exposes the underlying exception, improving debugging:

    Exception: Cannot open source device in php-src/test.php:17
    Stack trace:
    #0 php-src/test.php(17): Random\Randomizer->getInt(1, 3)
    #1 {main}

    Next RuntimeException: Random number generation failed in php-src/test.php:17
    Stack trace:
    #0 php-src/test.php(17): Random\Randomizer->getInt(1, 3)
    #1 {main}
  • Loading branch information
TimWolla committed Jul 20, 2022
commit b7bdf1aca647f9bf834a4224ef693131f25386bc
4 changes: 2 additions & 2 deletions ext/random/engine_secure.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ static uint64_t generate(php_random_status *status)

static zend_long range(php_random_status *status, zend_long min, zend_long max)
{
zend_long result;
zend_long result = 0;

if (php_random_int_silent(min, max, &result) == FAILURE) {
if (php_random_int_throw(min, max, &result) == FAILURE) {
status->last_unsafe = true;
}

Expand Down
0