Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions ext/session/php_session.h
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ typedef struct _php_ps_globals {
bool in_save_handler; /* state if session is in save handler or not */
bool set_handler; /* state if session module i setting handler or not */
zend_string *session_vars; /* serialized original session data */
bool random_seeded;
} php_ps_globals;

typedef php_ps_globals zend_ps_globals;
Expand Down
21 changes: 13 additions & 8 deletions ext/session/session.c
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,18 @@ static zend_long php_session_gc(bool immediate) /* {{{ */
/* GC must be done before reading session data. */
if ((PS(mod_data) || PS(mod_user_implemented))) {
if (!collect && PS(gc_probability) > 0) {
/* Seed lazily on first GC draw per process. */
if (UNEXPECTED(!PS(random_seeded))) {
php_random_uint128_t seed;
if (php_random_bytes_silent(&seed, sizeof(seed)) == FAILURE) {
seed = php_random_uint128_constant(
php_random_generate_fallback_seed(),
php_random_generate_fallback_seed()
);
}
php_random_pcgoneseq128xslrr64_seed128(PS(random).state, seed);
PS(random_seeded) = true;
}
collect = php_random_range(PS(random), 0, PS(gc_divisor) - 1) < PS(gc_probability);
}

Expand Down Expand Up @@ -2984,14 +2996,7 @@ static PHP_GINIT_FUNCTION(ps) /* {{{ */
.algo = &php_random_algo_pcgoneseq128xslrr64,
.state = &ps_globals->random_state,
};
php_random_uint128_t seed;
if (php_random_bytes_silent(&seed, sizeof(seed)) == FAILURE) {
seed = php_random_uint128_constant(
php_random_generate_fallback_seed(),
php_random_generate_fallback_seed()
);
}
php_random_pcgoneseq128xslrr64_seed128(ps_globals->random.state, seed);
ps_globals->random_seeded = false;
}
/* }}} */

Expand Down