Skip to content

Commit

Permalink
Update header handling to RFC 7230
Browse files Browse the repository at this point in the history
  • Loading branch information
smalyshev authored and Julien Pauli committed Feb 18, 2015
1 parent d8bc349 commit 996faf9
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 16 deletions.
7 changes: 4 additions & 3 deletions ext/standard/tests/general_functions/bug60227_2.phpt
@@ -1,14 +1,15 @@
--TEST--
Bug #60227 (header() cannot detect the multi-line header with CR), \r before \n
--INI--
expose_php=0
--FILE--
<?php
header("X-foo: e\n foo");
header("X-Foo6: e\rSet-Cookie: ID=123\n d");
echo 'foo';
?>
--EXPECTF--

Warning: Header may not contain more than a single header, new line detected in %s on line %d
foo
--EXPECTHEADERS--
X-foo: e
foo
Content-type: text/html; charset=UTF-8
6 changes: 3 additions & 3 deletions ext/standard/tests/general_functions/bug60227_3.phpt
@@ -1,14 +1,14 @@
--TEST--
Bug #60227 (header() cannot detect the multi-line header with CR), \0 before \n
--INI--
expose_php=0
--FILE--
<?php
header("X-foo: e\n foo");
header("X-Foo6: e\0Set-Cookie: ID=\n123\n d");
echo 'foo';
?>
--EXPECTF--
Warning: Header may not contain NUL bytes in %s on line %d
foo
--EXPECTHEADERS--
X-foo: e
foo
Content-type: text/html; charset=UTF-8
6 changes: 3 additions & 3 deletions ext/standard/tests/general_functions/bug60227_4.phpt
@@ -1,14 +1,14 @@
--TEST--
Bug #60227 (header() cannot detect the multi-line header with CR), CRLF
--INI--
expose_php=0
--FILE--
<?php
header("X-foo: e\r\nfoo");
header("X-foo: e\r\nfoo");
echo 'foo';
?>
--EXPECTF--
Warning: Header may not contain more than a single header, new line detected in %s on line %d
foo
--EXPECTHEADERS--
X-foo: e
foo
Content-type: text/html; charset=UTF-8
9 changes: 2 additions & 7 deletions main/SAPI.c
Expand Up @@ -743,13 +743,8 @@ SAPI_API int sapi_header_op(sapi_header_op_enum op, void *arg TSRMLS_DC)
/* new line/NUL character safety check */
int i;
for (i = 0; i < header_line_len; i++) {
/* RFC 2616 allows new lines if followed by SP or HT */
int illegal_break =
(header_line[i+1] != ' ' && header_line[i+1] != '\t')
&& (
header_line[i] == '\n'
|| (header_line[i] == '\r' && header_line[i+1] != '\n'));
if (illegal_break) {
/* RFC 7230 ch. 3.2.4 deprecates folding support */
if (header_line[i] == '\n' || header_line[i] == '\r') {
efree(header_line);
sapi_module.sapi_error(E_WARNING, "Header may not contain "
"more than a single header, new line detected");
Expand Down

0 comments on commit 996faf9

Please sign in to comment.