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