Skip to content

Commit cc797d4

Browse files
author
Yasuo Ohgaki
committed
Fix bug #72940 properly. Reduce needless branches
1 parent f93fd8c commit cc797d4

File tree

1 file changed

+38
-41
lines changed

1 file changed

+38
-41
lines changed

ext/session/session.c

Lines changed: 38 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1636,50 +1636,47 @@ PHPAPI void php_session_start(void) /* {{{ */
16361636
PS(define_sid) = 0;
16371637
}
16381638
}
1639-
1640-
if (PS(define_sid) && !PS(id) && (data = zend_hash_str_find(&EG(symbol_table), "_GET", sizeof("_GET") - 1))) {
1641-
ZVAL_DEREF(data);
1642-
if (Z_TYPE_P(data) == IS_ARRAY && (ppid = zend_hash_str_find(Z_ARRVAL_P(data), PS(session_name), lensess))) {
1643-
ppid2sid(ppid);
1639+
/* Initilize session ID from non cookie values */
1640+
if (!PS(use_only_cookies)) {
1641+
if (!PS(id) && (data = zend_hash_str_find(&EG(symbol_table), "_GET", sizeof("_GET") - 1))) {
1642+
ZVAL_DEREF(data);
1643+
if (Z_TYPE_P(data) == IS_ARRAY && (ppid = zend_hash_str_find(Z_ARRVAL_P(data), PS(session_name), lensess))) {
1644+
ppid2sid(ppid);
1645+
}
16441646
}
1645-
}
1646-
1647-
if (PS(define_sid) && !PS(id) && (data = zend_hash_str_find(&EG(symbol_table), "_POST", sizeof("_POST") - 1))) {
1648-
ZVAL_DEREF(data);
1649-
if (Z_TYPE_P(data) == IS_ARRAY && (ppid = zend_hash_str_find(Z_ARRVAL_P(data), PS(session_name), lensess))) {
1650-
ppid2sid(ppid);
1647+
if (!PS(id) && (data = zend_hash_str_find(&EG(symbol_table), "_POST", sizeof("_POST") - 1))) {
1648+
ZVAL_DEREF(data);
1649+
if (Z_TYPE_P(data) == IS_ARRAY && (ppid = zend_hash_str_find(Z_ARRVAL_P(data), PS(session_name), lensess))) {
1650+
ppid2sid(ppid);
1651+
}
16511652
}
1652-
}
1653-
1654-
/* Check the REQUEST_URI symbol for a string of the form
1655-
* '<session-name>=<session-id>' to allow URLs of the form
1656-
* http://yoursite/<session-name>=<session-id>/script.php */
1657-
if (PS(define_sid) && !PS(id) &&
1658-
zend_is_auto_global_str("_SERVER", sizeof("_SERVER") - 1) == SUCCESS &&
1659-
(data = zend_hash_str_find(Z_ARRVAL(PG(http_globals)[TRACK_VARS_SERVER]), "REQUEST_URI", sizeof("REQUEST_URI") - 1)) &&
1660-
Z_TYPE_P(data) == IS_STRING &&
1661-
(p = strstr(Z_STRVAL_P(data), PS(session_name))) &&
1662-
p[lensess] == '='
1663-
) {
1664-
char *q;
1665-
p += lensess + 1;
1666-
if ((q = strpbrk(p, "/?\\"))) {
1667-
PS(id) = zend_string_init(p, q - p, 0);
1653+
/* Check the REQUEST_URI symbol for a string of the form
1654+
* '<session-name>=<session-id>' to allow URLs of the form
1655+
* http://yoursite/<session-name>=<session-id>/script.php */
1656+
if (!PS(id) && zend_is_auto_global_str("_SERVER", sizeof("_SERVER") - 1) == SUCCESS &&
1657+
(data = zend_hash_str_find(Z_ARRVAL(PG(http_globals)[TRACK_VARS_SERVER]), "REQUEST_URI", sizeof("REQUEST_URI") - 1)) &&
1658+
Z_TYPE_P(data) == IS_STRING &&
1659+
(p = strstr(Z_STRVAL_P(data), PS(session_name))) &&
1660+
p[lensess] == '='
1661+
) {
1662+
char *q;
1663+
p += lensess + 1;
1664+
if ((q = strpbrk(p, "/?\\"))) {
1665+
PS(id) = zend_string_init(p, q - p, 0);
1666+
}
1667+
}
1668+
/* Check whether the current request was referred to by
1669+
* an external site which invalidates the previously found id. */
1670+
if (PS(id) && PS(extern_referer_chk)[0] != '\0' &&
1671+
!Z_ISUNDEF(PG(http_globals)[TRACK_VARS_SERVER]) &&
1672+
(data = zend_hash_str_find(Z_ARRVAL(PG(http_globals)[TRACK_VARS_SERVER]), "HTTP_REFERER", sizeof("HTTP_REFERER") - 1)) &&
1673+
Z_TYPE_P(data) == IS_STRING &&
1674+
Z_STRLEN_P(data) != 0 &&
1675+
strstr(Z_STRVAL_P(data), PS(extern_referer_chk)) == NULL
1676+
) {
1677+
zend_string_release(PS(id));
1678+
PS(id) = NULL;
16681679
}
1669-
}
1670-
1671-
/* Check whether the current request was referred to by
1672-
* an external site which invalidates the previously found id. */
1673-
if (PS(define_sid) && PS(id) &&
1674-
PS(extern_referer_chk)[0] != '\0' &&
1675-
!Z_ISUNDEF(PG(http_globals)[TRACK_VARS_SERVER]) &&
1676-
(data = zend_hash_str_find(Z_ARRVAL(PG(http_globals)[TRACK_VARS_SERVER]), "HTTP_REFERER", sizeof("HTTP_REFERER") - 1)) &&
1677-
Z_TYPE_P(data) == IS_STRING &&
1678-
Z_STRLEN_P(data) != 0 &&
1679-
strstr(Z_STRVAL_P(data), PS(extern_referer_chk)) == NULL
1680-
) {
1681-
zend_string_release(PS(id));
1682-
PS(id) = NULL;
16831680
}
16841681
}
16851682

0 commit comments

Comments
 (0)