Skip to content

Commit 36a7f48

Browse files
author
Yasuo Ohgaki
committed
Merge branch 'PHP-5.6'
* PHP-5.6: Fixed previous commit may delete unwanted cookies. Sync tests from upper branches. Re-fixed bug #66469
2 parents 9cefeea + 3cc6c6c commit 36a7f48

File tree

1 file changed

+45
-1
lines changed

1 file changed

+45
-1
lines changed

ext/session/session.c

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1297,6 +1297,49 @@ static int php_session_cache_limiter(TSRMLS_D) /* {{{ */
12971297
#define COOKIE_SECURE "; secure"
12981298
#define COOKIE_HTTPONLY "; HttpOnly"
12991299

1300+
/*
1301+
* Remove already sent session ID cookie.
1302+
* It must be directly removed from SG(sapi_header) because sapi_add_header_ex()
1303+
* removes all of matching cookie. i.e. It deletes all of Set-Cookie headers.
1304+
*/
1305+
static void php_session_remove_cookie() {
1306+
sapi_header_struct *header;
1307+
zend_llist *l = &SG(sapi_headers).headers;
1308+
zend_llist_element *next;
1309+
zend_llist_element *current;
1310+
char *session_cookie, *e_session_name;
1311+
int session_cookie_len, len = sizeof("Set-Cookie")-1;
1312+
1313+
e_session_name = php_url_encode(PS(session_name), strlen(PS(session_name)), NULL);
1314+
spprintf(&session_cookie, 0, "Set-Cookie: %s=", e_session_name);
1315+
efree(e_session_name);
1316+
1317+
session_cookie_len = strlen(session_cookie);
1318+
current = l->head;
1319+
while (current) {
1320+
header = (sapi_header_struct *)(current->data);
1321+
next = current->next;
1322+
if (header->header_len > len && header->header[len] == ':'
1323+
&& !strncmp(header->header, session_cookie, session_cookie_len)) {
1324+
if (current->prev) {
1325+
current->prev->next = next;
1326+
} else {
1327+
l->head = next;
1328+
}
1329+
if (next) {
1330+
next->prev = current->prev;
1331+
} else {
1332+
l->tail = current->prev;
1333+
}
1334+
sapi_free_header(header);
1335+
efree(current);
1336+
--l->count;
1337+
}
1338+
current = next;
1339+
}
1340+
efree(session_cookie);
1341+
}
1342+
13001343
static void php_session_send_cookie(TSRMLS_D) /* {{{ */
13011344
{
13021345
smart_str ncookie = {0};
@@ -1365,7 +1408,8 @@ static void php_session_send_cookie(TSRMLS_D) /* {{{ */
13651408

13661409
smart_str_0(&ncookie);
13671410

1368-
sapi_add_header_ex(ncookie.c, ncookie.len, 0, 1 TSRMLS_CC);
1411+
php_session_remove_cookie(); /* remove already sent session ID cookie */
1412+
sapi_add_header_ex(ncookie.c, ncookie.len, 0, 0 TSRMLS_CC);
13691413
}
13701414
/* }}} */
13711415

0 commit comments

Comments
 (0)