@@ -1068,9 +1068,10 @@ PHPAPI zend_result php_session_register_module(const ps_module *ptr) /* {{{ */
1068
1068
/* }}} */
1069
1069
1070
1070
/* Dummy PS module function */
1071
- /* We consider any ID valid, so we return FAILURE to indicate that a session doesn't exist */
1071
+ /* We consider any ID valid (thus also implying that a session with such an ID exists),
1072
+ thus we always return SUCCESS */
1072
1073
PHPAPI zend_result php_session_validate_sid (PS_VALIDATE_SID_ARGS ) {
1073
- return FAILURE ;
1074
+ return SUCCESS ;
1074
1075
}
1075
1076
1076
1077
/* Dummy PS module function */
@@ -2254,18 +2255,24 @@ PHP_FUNCTION(session_regenerate_id)
2254
2255
}
2255
2256
RETURN_THROWS ();
2256
2257
}
2257
- if (PS (use_strict_mode ) && PS (mod )-> s_validate_sid &&
2258
- PS (mod )-> s_validate_sid (& PS (mod_data ), PS (id )) == SUCCESS ) {
2259
- zend_string_release_ex (PS (id ), 0 );
2260
- PS (id ) = PS (mod )-> s_create_sid (& PS (mod_data ));
2261
- if (!PS (id )) {
2262
- PS (mod )-> s_close (& PS (mod_data ));
2263
- PS (session_status ) = php_session_none ;
2264
- if (!EG (exception )) {
2265
- zend_throw_error (NULL , "Failed to create session ID by collision: %s (path: %s)" , PS (mod )-> s_name , PS (save_path ));
2258
+ if (PS (use_strict_mode )) {
2259
+ if ((!PS (mod_user_implemented ) && PS (mod )-> s_validate_sid ) || !Z_ISUNDEF (PS (mod_user_names ).name .ps_validate_sid )) {
2260
+ int limit = 3 ;
2261
+ /* Try to generate non-existing ID */
2262
+ while (limit -- && PS (mod )-> s_validate_sid (& PS (mod_data ), PS (id )) == SUCCESS ) {
2263
+ zend_string_release_ex (PS (id ), 0 );
2264
+ PS (id ) = PS (mod )-> s_create_sid (& PS (mod_data ));
2265
+ if (!PS (id )) {
2266
+ PS (mod )-> s_close (& PS (mod_data ));
2267
+ PS (session_status ) = php_session_none ;
2268
+ if (!EG (exception )) {
2269
+ zend_throw_error (NULL , "Failed to create session ID by collision: %s (path: %s)" , PS (mod )-> s_name , PS (save_path ));
2270
+ }
2271
+ RETURN_THROWS ();
2272
+ }
2266
2273
}
2267
- RETURN_THROWS ();
2268
2274
}
2275
+ // TODO warn that ID cannot be verified? else { }
2269
2276
}
2270
2277
/* Read is required to make new session data at this point. */
2271
2278
if (PS (mod )-> s_read (& PS (mod_data ), PS (id ), & data , PS (gc_maxlifetime )) == FAILURE ) {
@@ -2292,7 +2299,6 @@ PHP_FUNCTION(session_regenerate_id)
2292
2299
/* }}} */
2293
2300
2294
2301
/* {{{ Generate new session ID. Intended for user save handlers. */
2295
- /* This is not used yet */
2296
2302
PHP_FUNCTION (session_create_id )
2297
2303
{
2298
2304
zend_string * prefix = NULL , * new_id ;
@@ -2316,7 +2322,7 @@ PHP_FUNCTION(session_create_id)
2316
2322
int limit = 3 ;
2317
2323
while (limit -- ) {
2318
2324
new_id = PS (mod )-> s_create_sid (& PS (mod_data ));
2319
- if (!PS (mod )-> s_validate_sid ) {
2325
+ if (!PS (mod )-> s_validate_sid || ( PS ( mod_user_implemented ) && Z_ISUNDEF ( PS ( mod_user_names ). name . ps_validate_sid )) ) {
2320
2326
break ;
2321
2327
} else {
2322
2328
/* Detect collision and retry */
0 commit comments