Skip to content

Commit db68565

Browse files
committed
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().
1 parent 62aa8fa commit db68565

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

ext/random/engine_pcgoneseq128xslrr64.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ PHP_METHOD(Random_Engine_PcgOneseq128XslRr64, __construct)
153153
ZEND_PARSE_PARAMETERS_END();
154154

155155
if (seed_is_null) {
156-
if (php_random_bytes_throw(&state->state, sizeof(php_random_uint128_t)) == FAILURE) {
156+
if (php_random_bytes_throw(&state->state, sizeof(state->state)) == FAILURE) {
157157
zend_throw_exception(random_ce_Random_RandomException, "Failed to generate a random seed", 0);
158158
RETURN_THROWS();
159159
}

ext/random/engine_xoshiro256starstar.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ PHP_METHOD(Random_Engine_Xoshiro256StarStar, __construct)
213213

214214
if (seed_is_null) {
215215
do {
216-
if (php_random_bytes_throw(&state->state, 32) == FAILURE) {
216+
if (php_random_bytes_throw(&state->state, sizeof(state->state)) == FAILURE) {
217217
zend_throw_exception(random_ce_Random_RandomException, "Failed to generate a random seed", 0);
218218
RETURN_THROWS();
219219
}

0 commit comments

Comments
 (0)