Skip to content

Commit 879c937

Browse files
committed
Merge branch 'PHP-7.1' into PHP-7.2
* PHP-7.1: Fix #76954: apache_response_headers removes last character from header name
2 parents 1b97f29 + 47b89bc commit 879c937

File tree

3 files changed

+52
-2
lines changed

3 files changed

+52
-2
lines changed

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ PHP NEWS
1313

1414
- FCGI:
1515
. Fixed #76948 (Failed shutdown/reboot or end session in Windows). (Anatol)
16+
. Fixed bug #76954 (apache_response_headers removes last character from header
17+
name). (stodorovic)
1618

1719
- FTP:
1820
. Fixed bug #76972 (Data truncation due to forceful ssl socket shutdown).

sapi/cgi/cgi_main.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1739,9 +1739,9 @@ static void add_response_header(sapi_header_struct *h, zval *return_value) /* {{
17391739
len = p - h->header;
17401740
}
17411741
if (len > 0) {
1742-
do {
1742+
while (len != 0 && (h->header[len-1] == ' ' || h->header[len-1] == '\t')) {
17431743
len--;
1744-
} while (len != 0 && (h->header[len-1] == ' ' || h->header[len-1] == '\t'));
1744+
}
17451745
if (len) {
17461746
s = do_alloca(len + 1, use_heap);
17471747
memcpy(s, h->header, len);
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
--TEST--
2+
apache_response_headers()
3+
--SKIPIF--
4+
<?php
5+
include "skipif.inc";
6+
?>
7+
--FILE--
8+
<?php
9+
include "include.inc";
10+
11+
$php = get_cgi_path();
12+
reset_env_vars();
13+
14+
$test_file = dirname(__FILE__) . DIRECTORY_SEPARATOR ."apache_response_headers.test.php";
15+
16+
$code = '<?php';
17+
$code .= '
18+
header( "X-Robots-Tag : noindex,nofollow,noarchive" );
19+
header( "Content-type: text/html; charset=UTF-8" );
20+
header( "Bad-header" );
21+
header( " : " );
22+
header( ":" );
23+
flush();
24+
25+
var_dump( apache_response_headers() );
26+
?>
27+
';
28+
29+
file_put_contents( $test_file, $code );
30+
31+
passthru( "$php -n -q " . escapeshellarg( $test_file ) );
32+
33+
?>
34+
===DONE===
35+
--CLEAN--
36+
<?php
37+
@unlink( dirname(__FILE__) . DIRECTORY_SEPARATOR ."apache_response_headers.test.php" );
38+
?>
39+
--EXPECTF--
40+
array(3) {
41+
["X-Powered-By"]=>
42+
string(%d) "PHP/%s"
43+
["X-Robots-Tag"]=>
44+
string(26) "noindex,nofollow,noarchive"
45+
["Content-type"]=>
46+
string(24) "text/html; charset=UTF-8"
47+
}
48+
===DONE===

0 commit comments

Comments
 (0)