Skip to content
Draft
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 @@ -183,6 +183,7 @@ typedef struct _php_ps_globals {
bool mod_user_is_open;
bool mod_user_uses_object_methods_as_handlers;
bool use_trans_sid; /* contains the INI value of whether to use trans-sid */
bool random_seeded;
} php_ps_globals;

typedef php_ps_globals zend_ps_globals;
Expand Down
22 changes: 13 additions & 9 deletions ext/session/session.c
Original file line number Diff line number Diff line change
Expand Up @@ -392,8 +392,19 @@ static zend_long php_session_gc(bool immediate)

/* GC must be done before reading session data. */
if ((PS(mod_data) || PS(mod_user_implemented))) {
/* Use probability-based GC if not forced and probability is configured */
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 @@ -2891,14 +2902,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;
}

static PHP_MINIT_FUNCTION(session)
Expand Down
Loading