Skip to content

Commit

Permalink
Fix #76954: apache_response_headers removes last character from heade…
Browse files Browse the repository at this point in the history
…r name
  • Loading branch information
stodorovic authored and cmb69 committed Oct 8, 2018
1 parent c097acd commit 47b89bc
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 2 deletions.
2 changes: 2 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ PHP NEWS
- FCGI:
. Fixed bug #76948 (Failed shutdown/reboot or end session in Windows).
(Anatol)
. Fixed bug #76954 (apache_response_headers removes last character from header
name). (stodorovic)

- FTP:
. Fixed bug #76972 (Data truncation due to forceful ssl socket shutdown).
Expand Down
4 changes: 2 additions & 2 deletions sapi/cgi/cgi_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -1735,9 +1735,9 @@ static void add_response_header(sapi_header_struct *h, zval *return_value) /* {{
len = p - h->header;
}
if (len > 0) {
do {
while (len != 0 && (h->header[len-1] == ' ' || h->header[len-1] == '\t')) {
len--;
} while (len != 0 && (h->header[len-1] == ' ' || h->header[len-1] == '\t'));
}
if (len) {
s = do_alloca(len + 1, use_heap);
memcpy(s, h->header, len);
Expand Down
48 changes: 48 additions & 0 deletions sapi/cgi/tests/apache_response_headers.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
--TEST--
apache_response_headers()
--SKIPIF--
<?php
include "skipif.inc";
?>
--FILE--
<?php
include "include.inc";

$php = get_cgi_path();
reset_env_vars();

$test_file = dirname(__FILE__) . DIRECTORY_SEPARATOR ."apache_response_headers.test.php";

$code = '<?php';
$code .= '
header( "X-Robots-Tag : noindex,nofollow,noarchive" );
header( "Content-type: text/html; charset=UTF-8" );
header( "Bad-header" );
header( " : " );
header( ":" );
flush();
var_dump( apache_response_headers() );
?>
';

file_put_contents( $test_file, $code );

passthru( "$php -n -q " . escapeshellarg( $test_file ) );

?>
===DONE===
--CLEAN--
<?php
@unlink( dirname(__FILE__) . DIRECTORY_SEPARATOR ."apache_response_headers.test.php" );
?>
--EXPECTF--
array(3) {
["X-Powered-By"]=>
string(%d) "PHP/%s"
["X-Robots-Tag"]=>
string(26) "noindex,nofollow,noarchive"
["Content-type"]=>
string(24) "text/html; charset=UTF-8"
}
===DONE===

0 comments on commit 47b89bc

Please sign in to comment.