Skip to content

Commit f2ab035

Browse files
committed
Fix regression with header removing removing whole prefixes
The header removal code looked for the colon for key-value at the wrong place, so it would overzealously remove headers. Tweak that condition, and make the alternative condition only active if it's set (with the remove prefix op case). Fixes GH-21018.
1 parent 2c08d9a commit f2ab035

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
--TEST--
2+
GH-21018 (header() removes headers with the same prefix)
3+
--INI--
4+
expose_php=On
5+
--CGI--
6+
--FILE--
7+
<?php
8+
header('a: 1');
9+
header('a-test: 1');
10+
header('a: 1');
11+
var_dump(headers_list());
12+
?>
13+
--EXPECTF--
14+
array(3) {
15+
[0]=>
16+
string(%d) "X-Powered-By: PHP/%s"
17+
[1]=>
18+
string(9) "a-test: 1"
19+
[2]=>
20+
string(4) "a: 1"
21+
}

main/SAPI.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -610,8 +610,12 @@ static void sapi_remove_header(zend_llist *l, char *name, size_t len, size_t hea
610610
while (current) {
611611
header = (sapi_header_struct *)(current->data);
612612
next = current->next;
613+
/*
614+
* header_len is set for DELETE_PREFIX (used in cookies)
615+
* look for the : otherwise
616+
*/
613617
if (header->header_len > header_len
614-
&& (header->header[header_len] == ':' || len > header_len)
618+
&& (header->header[len] == ':' || (header_len && len > header_len))
615619
&& !strncasecmp(header->header, name, len)) {
616620
if (current->prev) {
617621
current->prev->next = next;

0 commit comments

Comments
 (0)