4 ms·
Amusingly, after months of pointless bikeshedding, we managed to convince the internals team to throw an exception during the extreme case of a CSPRNG failure.
by sarciszewski 11y ago
Amusingly, after months of pointless bikeshedding, we managed to convince the internals team to throw an exception during the extreme case of a CSPRNG failure.
https://www.sammyk.me/security-changes-to-the-php-7-csprng-in-rc3 https://www.sammyk.me/security-changes-to-the-php-7-csprng-i...
You can read my arguments on the mailing list, but basically it amounted to:
$chars = 'abcdefghijklmnopqrstuvwxyz234567';
for ($i = 0; $i < 12; ++$i) {
$password .= $chars[random_int(0, 31)];
}
If random_int() returned FALSE, $password would be the string 'aaaaaaaaaaaa' (and you'd have 12 E_WARNING errors in your log).
By making it an exception, random_int() will now fail closed (kill the script by default), but the developer can still handle it gracefully.
$chars = 'abcdefghijklmnopqrstuvwxyz234567';
try {
for ($i = 0; $i < 12; ++$i) {
$password .= $chars[random_int(0, 31)];
}
} catch (Throwable $e) {
$framework->template->kill('An unrecoverable fatal error occurred.');
}
Or something similar.
Is it a BC break? Sure. Is it worth it? Oh yeah.
- debacle 11y agoWe need more BC breaks, not fewer. I'd really like to see a lot of functions that return FALSE on failure throw exceptions in the future. We could also tidy up the stdlib a bit and give primatives some OO love. If you're going to break BC, might as well do it right.
- sarciszewski 11y agoSo, onwards to PHP (gr)8?
- debacle 11y agoI'm hoping Hack can liberate us.