@@ -416,7 +416,7 @@ static zend_result php_session_initialize(void) /* {{{ */
416
416
}
417
417
418
418
/* Open session handler first */
419
- if (PS (mod )-> s_open (& PS (mod_data ), PS (save_path ), PS (session_name )) == FAILURE
419
+ if (PS (mod )-> s_open (& PS (mod_data ), PS (save_path ), ZSTR_VAL ( PS (session_name ) )) == FAILURE
420
420
/* || PS(mod_data) == NULL */ /* FIXME: open must set valid PS(mod_data) with success */
421
421
) {
422
422
php_session_abort ();
@@ -681,24 +681,41 @@ static PHP_INI_MH(OnUpdateName) /* {{{ */
681
681
SESSION_CHECK_ACTIVE_STATE ;
682
682
SESSION_CHECK_OUTPUT_STATE ;
683
683
684
- /* Numeric session.name won't work at all */
685
- if ((!ZSTR_LEN (new_value ) || is_numeric_string (ZSTR_VAL (new_value ), ZSTR_LEN (new_value ), NULL , NULL , 0 ))) {
686
- int err_type ;
684
+ int err_type ;
687
685
688
- if (stage == ZEND_INI_STAGE_RUNTIME || stage == ZEND_INI_STAGE_ACTIVATE || stage == ZEND_INI_STAGE_STARTUP ) {
689
- err_type = E_WARNING ;
690
- } else {
691
- err_type = E_ERROR ;
692
- }
686
+ if (stage == ZEND_INI_STAGE_RUNTIME || stage == ZEND_INI_STAGE_ACTIVATE || stage == ZEND_INI_STAGE_STARTUP ) {
687
+ err_type = E_WARNING ;
688
+ } else {
689
+ err_type = E_ERROR ;
690
+ }
693
691
692
+ if (ZSTR_LEN (new_value ) == 0 ) {
693
+ /* Do not output error when restoring ini options. */
694
+ if (stage != ZEND_INI_STAGE_DEACTIVATE ) {
695
+ php_error_docref (NULL , err_type , "session.name \"%s\" cannot be empty" , ZSTR_VAL (new_value ));
696
+ }
697
+ return FAILURE ;
698
+ }
699
+ /* Nul bytes are not allowed */
700
+ if (ZSTR_LEN (new_value ) != strlen (ZSTR_VAL (new_value ))) {
701
+ /* Do not output error when restoring ini options. */
702
+ if (stage != ZEND_INI_STAGE_DEACTIVATE ) {
703
+ php_error_docref (NULL , err_type , "session.name \"%s\" cannot contain nul bytes" , ZSTR_VAL (new_value ));
704
+ }
705
+ return FAILURE ;
706
+ }
707
+ /* Numeric session.name won't work at all */
708
+ if (is_numeric_str_function (new_value , NULL , NULL )) {
694
709
/* Do not output error when restoring ini options. */
695
710
if (stage != ZEND_INI_STAGE_DEACTIVATE ) {
696
711
php_error_docref (NULL , err_type , "session.name \"%s\" cannot be numeric or empty" , ZSTR_VAL (new_value ));
697
712
}
698
713
return FAILURE ;
699
714
}
700
715
701
- return OnUpdateStringUnempty (entry , new_value , mh_arg1 , mh_arg2 , mh_arg3 , stage );
716
+ zend_string * * p = (zend_string * * ) ZEND_INI_GET_ADDR ();
717
+ * p = new_value ;
718
+ return SUCCESS ;
702
719
}
703
720
/* }}} */
704
721
@@ -1372,9 +1389,10 @@ static void php_session_remove_cookie(void) {
1372
1389
size_t session_cookie_len ;
1373
1390
size_t len = sizeof ("Set-Cookie" )- 1 ;
1374
1391
1375
- ZEND_ASSERT (strpbrk (PS (session_name ), SESSION_FORBIDDEN_CHARS ) == NULL );
1376
- spprintf (& session_cookie , 0 , "Set-Cookie: %s=" , PS (session_name ));
1392
+ ZEND_ASSERT (strpbrk (ZSTR_VAL ( PS (session_name ) ), SESSION_FORBIDDEN_CHARS ) == NULL );
1393
+ spprintf (& session_cookie , 0 , "Set-Cookie: %s=" , ZSTR_VAL ( PS (session_name ) ));
1377
1394
1395
+ // TODO Manually compute from known information?
1378
1396
session_cookie_len = strlen (session_cookie );
1379
1397
current = l -> head ;
1380
1398
while (current ) {
@@ -1419,17 +1437,18 @@ static zend_result php_session_send_cookie(void) /* {{{ */
1419
1437
return FAILURE ;
1420
1438
}
1421
1439
1440
+ // TODO need to Check for nul byte?
1422
1441
/* Prevent broken Set-Cookie header, because the session_name might be user supplied */
1423
- if (strpbrk (PS (session_name ), SESSION_FORBIDDEN_CHARS ) != NULL ) { /* man isspace for \013 and \014 */
1424
- php_error_docref (NULL , E_WARNING , "session.name cannot contain any of the following '=,;.[ \\t\\r\\n\\013\\014'" );
1442
+ if (strpbrk (ZSTR_VAL ( PS (session_name ) ), SESSION_FORBIDDEN_CHARS ) != NULL ) { /* man isspace for \013 and \014 */
1443
+ php_error_docref (NULL , E_WARNING , "session.name cannot contain any of the following '=,; \\t\\r\\n\\013\\014'" );
1425
1444
return FAILURE ;
1426
1445
}
1427
1446
1428
1447
/* URL encode id because it might be user supplied */
1429
1448
e_id = php_url_encode (ZSTR_VAL (PS (id )), ZSTR_LEN (PS (id )));
1430
1449
1431
1450
smart_str_appendl (& ncookie , "Set-Cookie: " , sizeof ("Set-Cookie: " )- 1 );
1432
- smart_str_appendl (& ncookie , PS (session_name ), strlen ( PS ( session_name ) ));
1451
+ smart_str_append (& ncookie , PS (session_name ));
1433
1452
smart_str_appendc (& ncookie , '=' );
1434
1453
smart_str_appendl (& ncookie , ZSTR_VAL (e_id ), ZSTR_LEN (e_id ));
1435
1454
@@ -1555,7 +1574,7 @@ PHPAPI zend_result php_session_reset_id(void) /* {{{ */
1555
1574
if (PS (define_sid )) {
1556
1575
smart_str var = {0 };
1557
1576
1558
- smart_str_appends (& var , PS (session_name ));
1577
+ smart_str_append (& var , PS (session_name ));
1559
1578
smart_str_appendc (& var , '=' );
1560
1579
smart_str_appends (& var , ZSTR_VAL (PS (id )));
1561
1580
smart_str_0 (& var );
@@ -1583,18 +1602,15 @@ PHPAPI zend_result php_session_reset_id(void) /* {{{ */
1583
1602
(data = zend_hash_str_find (& EG (symbol_table ), "_COOKIE" , sizeof ("_COOKIE" ) - 1 ))) {
1584
1603
ZVAL_DEREF (data );
1585
1604
if (Z_TYPE_P (data ) == IS_ARRAY &&
1586
- (ppid = zend_hash_str_find (Z_ARRVAL_P (data ), PS (session_name ), strlen ( PS ( session_name ) )))) {
1605
+ (ppid = zend_hash_find (Z_ARRVAL_P (data ), PS (session_name )))) {
1587
1606
ZVAL_DEREF (ppid );
1588
1607
apply_trans_sid = 0 ;
1589
1608
}
1590
1609
}
1591
1610
}
1592
1611
if (apply_trans_sid ) {
1593
- zend_string * sname ;
1594
- sname = zend_string_init (PS (session_name ), strlen (PS (session_name )), 0 );
1595
- php_url_scanner_reset_session_var (sname , 1 ); /* This may fail when session name has changed */
1596
- zend_string_release_ex (sname , 0 );
1597
- php_url_scanner_add_session_var (PS (session_name ), strlen (PS (session_name )), ZSTR_VAL (PS (id )), ZSTR_LEN (PS (id )), 1 );
1612
+ php_url_scanner_reset_session_var (PS (session_name ), 1 ); /* This may fail when session name has changed */
1613
+ php_url_scanner_add_session_var (ZSTR_VAL (PS (session_name )), ZSTR_LEN (PS (session_name )), ZSTR_VAL (PS (id )), ZSTR_LEN (PS (id )), 1 );
1598
1614
}
1599
1615
return SUCCESS ;
1600
1616
}
@@ -1605,8 +1621,7 @@ PHPAPI zend_result php_session_start(void) /* {{{ */
1605
1621
{
1606
1622
zval * ppid ;
1607
1623
zval * data ;
1608
- char * value ;
1609
- size_t lensess ;
1624
+ char * p , * value ;
1610
1625
1611
1626
switch (PS (session_status )) {
1612
1627
case php_session_active :
@@ -1648,8 +1663,6 @@ PHPAPI zend_result php_session_start(void) /* {{{ */
1648
1663
PS (send_cookie ) = PS (use_cookies ) || PS (use_only_cookies );
1649
1664
}
1650
1665
1651
- lensess = strlen (PS (session_name ));
1652
-
1653
1666
/*
1654
1667
* Cookies are preferred, because initially cookie and get
1655
1668
* variables will be available.
@@ -1661,7 +1674,7 @@ PHPAPI zend_result php_session_start(void) /* {{{ */
1661
1674
if (!PS (id )) {
1662
1675
if (PS (use_cookies ) && (data = zend_hash_str_find (& EG (symbol_table ), "_COOKIE" , sizeof ("_COOKIE" ) - 1 ))) {
1663
1676
ZVAL_DEREF (data );
1664
- if (Z_TYPE_P (data ) == IS_ARRAY && (ppid = zend_hash_str_find (Z_ARRVAL_P (data ), PS (session_name ), lensess ))) {
1677
+ if (Z_TYPE_P (data ) == IS_ARRAY && (ppid = zend_hash_find (Z_ARRVAL_P (data ), PS (session_name )))) {
1665
1678
ppid2sid (ppid );
1666
1679
PS (send_cookie ) = 0 ;
1667
1680
PS (define_sid ) = 0 ;
@@ -1671,16 +1684,31 @@ PHPAPI zend_result php_session_start(void) /* {{{ */
1671
1684
if (!PS (use_only_cookies )) {
1672
1685
if (!PS (id ) && (data = zend_hash_str_find (& EG (symbol_table ), "_GET" , sizeof ("_GET" ) - 1 ))) {
1673
1686
ZVAL_DEREF (data );
1674
- if (Z_TYPE_P (data ) == IS_ARRAY && (ppid = zend_hash_str_find (Z_ARRVAL_P (data ), PS (session_name ), lensess ))) {
1687
+ if (Z_TYPE_P (data ) == IS_ARRAY && (ppid = zend_hash_find (Z_ARRVAL_P (data ), PS (session_name )))) {
1675
1688
ppid2sid (ppid );
1676
1689
}
1677
1690
}
1678
1691
if (!PS (id ) && (data = zend_hash_str_find (& EG (symbol_table ), "_POST" , sizeof ("_POST" ) - 1 ))) {
1679
1692
ZVAL_DEREF (data );
1680
- if (Z_TYPE_P (data ) == IS_ARRAY && (ppid = zend_hash_str_find (Z_ARRVAL_P (data ), PS (session_name ), lensess ))) {
1693
+ if (Z_TYPE_P (data ) == IS_ARRAY && (ppid = zend_hash_find (Z_ARRVAL_P (data ), PS (session_name )))) {
1681
1694
ppid2sid (ppid );
1682
1695
}
1683
1696
}
1697
+ /* Check the REQUEST_URI symbol for a string of the form
1698
+ * '<session-name>=<session-id>' to allow URLs of the form
1699
+ * http://yoursite/<session-name>=<session-id>/script.php */
1700
+ if (!PS (id ) && zend_is_auto_global (ZSTR_KNOWN (ZEND_STR_AUTOGLOBAL_SERVER )) == SUCCESS &&
1701
+ (data = zend_hash_str_find (Z_ARRVAL (PG (http_globals )[TRACK_VARS_SERVER ]), "REQUEST_URI" , sizeof ("REQUEST_URI" ) - 1 )) &&
1702
+ Z_TYPE_P (data ) == IS_STRING &&
1703
+ (p = strstr (Z_STRVAL_P (data ), ZSTR_VAL (PS (session_name )))) &&
1704
+ p [ZSTR_LEN (PS (session_name ))] == '='
1705
+ ) {
1706
+ char * q ;
1707
+ p += ZSTR_LEN (PS (session_name ));
1708
+ if ((q = strpbrk (p , "/?\\" ))) {
1709
+ PS (id ) = zend_string_init (p , q - p , 0 );
1710
+ }
1711
+ }
1684
1712
/* Check whether the current request was referred to by
1685
1713
* an external site which invalidates the previously found id. */
1686
1714
if (PS (id ) && PS (extern_referer_chk ) && ZSTR_LEN (PS (extern_referer_chk )) != 0 &&
@@ -1763,7 +1791,7 @@ static zend_result php_session_reset(void) /* {{{ */
1763
1791
PHPAPI void session_adapt_url (const char * url , size_t url_len , char * * new_url , size_t * new_len ) /* {{{ */
1764
1792
{
1765
1793
if (APPLY_TRANS_SID && (PS (session_status ) == php_session_active )) {
1766
- * new_url = php_url_scanner_adapt_single_url (url , url_len , PS (session_name ), ZSTR_VAL (PS (id )), new_len , 1 );
1794
+ * new_url = php_url_scanner_adapt_single_url (url , url_len , ZSTR_VAL ( PS (session_name ) ), ZSTR_VAL (PS (id )), new_len , 1 );
1767
1795
}
1768
1796
}
1769
1797
/* }}} */
@@ -1985,7 +2013,8 @@ PHP_FUNCTION(session_name)
1985
2013
RETURN_FALSE ;
1986
2014
}
1987
2015
1988
- RETVAL_STRING (PS (session_name ));
2016
+ // TODO Prevent duplication???
2017
+ RETVAL_STR (zend_string_dup (PS (session_name ), false));
1989
2018
1990
2019
if (name ) {
1991
2020
ini_name = ZSTR_INIT_LITERAL ("session.name" , 0 );
@@ -2403,7 +2432,7 @@ PHP_FUNCTION(session_regenerate_id)
2403
2432
zend_string_release_ex (PS (id ), 0 );
2404
2433
PS (id ) = NULL ;
2405
2434
2406
- if (PS (mod )-> s_open (& PS (mod_data ), PS (save_path ), PS (session_name )) == FAILURE ) {
2435
+ if (PS (mod )-> s_open (& PS (mod_data ), PS (save_path ), ZSTR_VAL ( PS (session_name ) )) == FAILURE ) {
2407
2436
PS (session_status ) = php_session_none ;
2408
2437
if (!EG (exception )) {
2409
2438
zend_throw_error (NULL , "Failed to open session: %s (path: %s)" , PS (mod )-> s_name , PS (save_path ));
@@ -3117,7 +3146,7 @@ static bool early_find_sid_in(zval *dest, int where, php_session_rfc1867_progres
3117
3146
return 0 ;
3118
3147
}
3119
3148
3120
- if ((ppid = zend_hash_str_find (Z_ARRVAL (PG (http_globals )[where ]), PS (session_name ), progress -> sname_len ))
3149
+ if ((ppid = zend_hash_find (Z_ARRVAL (PG (http_globals )[where ]), PS (session_name )))
3121
3150
&& Z_TYPE_P (ppid ) == IS_STRING ) {
3122
3151
zval_ptr_dtor (dest );
3123
3152
ZVAL_COPY_DEREF (dest , ppid );
@@ -3225,7 +3254,8 @@ static zend_result php_session_rfc1867_callback(unsigned int event, void *event_
3225
3254
multipart_event_start * data = (multipart_event_start * ) event_data ;
3226
3255
progress = ecalloc (1 , sizeof (php_session_rfc1867_progress ));
3227
3256
progress -> content_length = data -> content_length ;
3228
- progress -> sname_len = strlen (PS (session_name ));
3257
+ // TODO Remove field?
3258
+ progress -> sname_len = ZSTR_LEN (PS (session_name ));
3229
3259
PS (rfc1867_progress ) = progress ;
3230
3260
}
3231
3261
break ;
@@ -3247,7 +3277,7 @@ static zend_result php_session_rfc1867_callback(unsigned int event, void *event_
3247
3277
if (data -> name && data -> value && value_len ) {
3248
3278
size_t name_len = strlen (data -> name );
3249
3279
3250
- if (name_len == progress -> sname_len && memcmp (data -> name , PS (session_name ), name_len ) == 0 ) {
3280
+ if (name_len == progress -> sname_len && memcmp (data -> name , ZSTR_VAL ( PS (session_name ) ), name_len ) == 0 ) {
3251
3281
zval_ptr_dtor (& progress -> sid );
3252
3282
ZVAL_STRINGL (& progress -> sid , (* data -> value ), value_len );
3253
3283
} else if (name_len == strlen (PS (rfc1867_name )) && memcmp (data -> name , PS (rfc1867_name ), name_len + 1 ) == 0 ) {
0 commit comments