From a27e51fd4e9121f962821d0f7bd1960fce0a0fd5 Mon Sep 17 00:00:00 2001 From: Yasuo Ohgaki Date: Wed, 22 Jan 2014 13:40:58 +0900 Subject: Re-fixed bug #66469 --- ext/session/session.c | 4 +--- ext/session/tests/bug60634.phpt | 3 +-- ext/session/tests/bug60634_error_1.phpt | 3 +-- ext/session/tests/bug60634_error_2.phpt | 7 +++++-- ext/session/tests/bug60634_error_3.phpt | 3 +-- ext/session/tests/bug60634_error_4.phpt | 7 +++++-- 6 files changed, 14 insertions(+), 13 deletions(-) diff --git a/ext/session/session.c b/ext/session/session.c index 5b03d6362e..d6d5da2d0c 100644 --- a/ext/session/session.c +++ b/ext/session/session.c @@ -1248,9 +1248,7 @@ static void php_session_send_cookie(TSRMLS_D) /* {{{ */ smart_str_0(&ncookie); - /* 'replace' must be 0 here, else a previous Set-Cookie - header, probably sent with setcookie() will be replaced! */ - sapi_add_header_ex(ncookie.c, ncookie.len, 0, 0 TSRMLS_CC); + sapi_add_header_ex(ncookie.c, ncookie.len, 0, 1 TSRMLS_CC); } /* }}} */ diff --git a/ext/session/tests/bug60634.phpt b/ext/session/tests/bug60634.phpt index 2ec0c26c13..69f3db4faa 100644 --- a/ext/session/tests/bug60634.phpt +++ b/ext/session/tests/bug60634.phpt @@ -1,7 +1,5 @@ --TEST-- Bug #60634 (Segmentation fault when trying to die() in SessionHandler::write()) ---XFAIL-- -Long term low priority bug, working on it --INI-- session.save_path= session.name=PHPSESSID @@ -44,3 +42,4 @@ echo "um, hi\n"; ?> --EXPECTF-- write: goodbye cruel world +close: goodbye cruel world \ No newline at end of file diff --git a/ext/session/tests/bug60634_error_1.phpt b/ext/session/tests/bug60634_error_1.phpt index 3b6e394eed..e41592f18d 100644 --- a/ext/session/tests/bug60634_error_1.phpt +++ b/ext/session/tests/bug60634_error_1.phpt @@ -1,7 +1,5 @@ --TEST-- Bug #60634 (Segmentation fault when trying to die() in SessionHandler::write()) - fatal error in write during exec ---XFAIL-- -Long term low priority bug, working on it --INI-- session.save_path= session.name=PHPSESSID @@ -47,3 +45,4 @@ echo "um, hi\n"; write: goodbye cruel world Fatal error: Call to undefined function undefined_function() in %s on line %d +close: goodbye cruel world diff --git a/ext/session/tests/bug60634_error_2.phpt b/ext/session/tests/bug60634_error_2.phpt index 265fb303f7..8ab0242b62 100644 --- a/ext/session/tests/bug60634_error_2.phpt +++ b/ext/session/tests/bug60634_error_2.phpt @@ -1,7 +1,5 @@ --TEST-- Bug #60634 (Segmentation fault when trying to die() in SessionHandler::write()) - exception in write during exec ---XFAIL-- -Long term low priority bug, working on it --INI-- session.save_path= session.name=PHPSESSID @@ -47,3 +45,8 @@ echo "um, hi\n"; write: goodbye cruel world Fatal error: Uncaught exception 'Exception' in %s +Stack trace: +#0 [internal function]: write('%s', '') +#1 %s/ext/session/tests/bug60634_error_2.php(32): session_write_close() +#2 {main} + thrown in %s/ext/session/tests/bug60634_error_2.php on line 19 \ No newline at end of file diff --git a/ext/session/tests/bug60634_error_3.phpt b/ext/session/tests/bug60634_error_3.phpt index b2004d68bc..4a508a4d8f 100644 --- a/ext/session/tests/bug60634_error_3.phpt +++ b/ext/session/tests/bug60634_error_3.phpt @@ -1,7 +1,5 @@ --TEST-- Bug #60634 (Segmentation fault when trying to die() in SessionHandler::write()) - fatal error in write after exec ---XFAIL-- -Long term low priority bug, working on it --INI-- session.save_path= session.name=PHPSESSID @@ -46,3 +44,4 @@ session_start(); write: goodbye cruel world Fatal error: Call to undefined function undefined_function() in %s on line %d +close: goodbye cruel world diff --git a/ext/session/tests/bug60634_error_4.phpt b/ext/session/tests/bug60634_error_4.phpt index 60bc0dcf54..d5e81b8abf 100644 --- a/ext/session/tests/bug60634_error_4.phpt +++ b/ext/session/tests/bug60634_error_4.phpt @@ -1,7 +1,5 @@ --TEST-- Bug #60634 (Segmentation fault when trying to die() in SessionHandler::write()) - exception in write after exec ---XFAIL-- -Long term low priority bug, working on it --INI-- session.save_path= session.name=PHPSESSID @@ -46,3 +44,8 @@ session_start(); write: goodbye cruel world Fatal error: Uncaught exception 'Exception' in %s +Stack trace: +#0 [internal function]: write('%s', '') +#1 {main} + thrown in %s/ext/session/tests/bug60634_error_4.php on line 20 +close: goodbye cruel world \ No newline at end of file -- cgit v1.2.1 From 58f94345a7ef8125d5c7a5a3dfe23a7c50a8bfcd Mon Sep 17 00:00:00 2001 From: Yasuo Ohgaki Date: Wed, 22 Jan 2014 19:21:25 +0900 Subject: Fixed previous commit may delete unwanted cookies. Sync tests from upper branches. --- ext/session/session.c | 46 ++++++++++++++++++++++++++++++++- ext/session/tests/bug60634.phpt | 3 ++- ext/session/tests/bug60634_error_2.phpt | 4 +-- ext/session/tests/bug60634_error_4.phpt | 5 ++-- 4 files changed, 52 insertions(+), 6 deletions(-) diff --git a/ext/session/session.c b/ext/session/session.c index d6d5da2d0c..afc7eef56c 100644 --- a/ext/session/session.c +++ b/ext/session/session.c @@ -1183,6 +1183,49 @@ static int php_session_cache_limiter(TSRMLS_D) /* {{{ */ #define COOKIE_SECURE "; secure" #define COOKIE_HTTPONLY "; HttpOnly" +/* + * Remove already sent session ID cookie. + * It must be directly removed from SG(sapi_header) because sapi_add_header_ex() + * removes all of matching cookie. i.e. It deletes all of Set-Cookie headers. + */ +static void php_session_remove_cookie() { + sapi_header_struct *header; + zend_llist *l = &SG(sapi_headers).headers; + zend_llist_element *next; + zend_llist_element *current; + char *session_cookie, *e_session_name; + int session_cookie_len, len = sizeof("Set-Cookie")-1; + + e_session_name = php_url_encode(PS(session_name), strlen(PS(session_name)), NULL); + spprintf(&session_cookie, 0, "Set-Cookie: %s=", e_session_name); + efree(e_session_name); + + session_cookie_len = strlen(session_cookie); + current = l->head; + while (current) { + header = (sapi_header_struct *)(current->data); + next = current->next; + if (header->header_len > len && header->header[len] == ':' + && !strncmp(header->header, session_cookie, session_cookie_len)) { + if (current->prev) { + current->prev->next = next; + } else { + l->head = next; + } + if (next) { + next->prev = current->prev; + } else { + l->tail = current->prev; + } + sapi_free_header(header); + efree(current); + --l->count; + } + current = next; + } + efree(session_cookie); +} + static void php_session_send_cookie(TSRMLS_D) /* {{{ */ { smart_str ncookie = {0}; @@ -1248,7 +1291,8 @@ static void php_session_send_cookie(TSRMLS_D) /* {{{ */ smart_str_0(&ncookie); - sapi_add_header_ex(ncookie.c, ncookie.len, 0, 1 TSRMLS_CC); + php_session_remove_cookie(); /* remove already sent session ID cookie */ + sapi_add_header_ex(ncookie.c, ncookie.len, 0, 0 TSRMLS_CC); } /* }}} */ diff --git a/ext/session/tests/bug60634.phpt b/ext/session/tests/bug60634.phpt index 69f3db4faa..86dcb11526 100644 --- a/ext/session/tests/bug60634.phpt +++ b/ext/session/tests/bug60634.phpt @@ -42,4 +42,5 @@ echo "um, hi\n"; ?> --EXPECTF-- write: goodbye cruel world -close: goodbye cruel world \ No newline at end of file +close: goodbye cruel world + diff --git a/ext/session/tests/bug60634_error_2.phpt b/ext/session/tests/bug60634_error_2.phpt index 8ab0242b62..7c50948ba8 100644 --- a/ext/session/tests/bug60634_error_2.phpt +++ b/ext/session/tests/bug60634_error_2.phpt @@ -47,6 +47,6 @@ write: goodbye cruel world Fatal error: Uncaught exception 'Exception' in %s Stack trace: #0 [internal function]: write('%s', '') -#1 %s/ext/session/tests/bug60634_error_2.php(32): session_write_close() +#1 %s(%d): session_write_close() #2 {main} - thrown in %s/ext/session/tests/bug60634_error_2.php on line 19 \ No newline at end of file + thrown in %s on line %d diff --git a/ext/session/tests/bug60634_error_4.phpt b/ext/session/tests/bug60634_error_4.phpt index d5e81b8abf..d0b5786af9 100644 --- a/ext/session/tests/bug60634_error_4.phpt +++ b/ext/session/tests/bug60634_error_4.phpt @@ -47,5 +47,6 @@ Fatal error: Uncaught exception 'Exception' in %s Stack trace: #0 [internal function]: write('%s', '') #1 {main} - thrown in %s/ext/session/tests/bug60634_error_4.php on line 20 -close: goodbye cruel world \ No newline at end of file + thrown in %s on line %d +close: goodbye cruel world + -- cgit v1.2.1