1
0
mirror of https://github.com/php/php-src.git synced 2026-03-24 00:02:20 +01:00

random: Dynamically calculate the state size when seeding with CSPRNG

Instead of hardcoding struct names, or even sizes, we can just determine the
actual size of the target structure using sizeof().
This commit is contained in:
Tim Düsterhus
2024-01-09 20:12:50 +01:00
committed by Tim Düsterhus
parent 62aa8fa375
commit db68565d03
2 changed files with 2 additions and 2 deletions

View File

@@ -153,7 +153,7 @@ PHP_METHOD(Random_Engine_PcgOneseq128XslRr64, __construct)
ZEND_PARSE_PARAMETERS_END();
if (seed_is_null) {
if (php_random_bytes_throw(&state->state, sizeof(php_random_uint128_t)) == FAILURE) {
if (php_random_bytes_throw(&state->state, sizeof(state->state)) == FAILURE) {
zend_throw_exception(random_ce_Random_RandomException, "Failed to generate a random seed", 0);
RETURN_THROWS();
}

View File

@@ -213,7 +213,7 @@ PHP_METHOD(Random_Engine_Xoshiro256StarStar, __construct)
if (seed_is_null) {
do {
if (php_random_bytes_throw(&state->state, 32) == FAILURE) {
if (php_random_bytes_throw(&state->state, sizeof(state->state)) == FAILURE) {
zend_throw_exception(random_ce_Random_RandomException, "Failed to generate a random seed", 0);
RETURN_THROWS();
}