summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristoph M. Becker <cmbecker69@gmx.de>2018-10-08 12:30:14 +0200
committerChristoph M. Becker <cmbecker69@gmx.de>2018-10-08 12:30:45 +0200
commit879c937a272328d9d333a4188acc98b53f45fcb1 (patch)
tree22f8602d88ff0f0051f2b230d6d54f2d9478aab6
parent1b97f291a726480bc1db8b7a06a55663f316ded5 (diff)
parent47b89bc5314534e4aab4a8d6cda0da9d079366f6 (diff)
downloadphp-git-879c937a272328d9d333a4188acc98b53f45fcb1.tar.gz
Merge branch 'PHP-7.1' into PHP-7.2
* PHP-7.1: Fix #76954: apache_response_headers removes last character from header name
-rw-r--r--NEWS2
-rw-r--r--sapi/cgi/cgi_main.c4
-rw-r--r--sapi/cgi/tests/apache_response_headers.phpt48
3 files changed, 52 insertions, 2 deletions
diff --git a/NEWS b/NEWS
index 1776413bf2..e4429f7a9b 100644
--- a/NEWS
+++ b/NEWS
@@ -13,6 +13,8 @@ PHP NEWS
- FCGI:
. Fixed #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).
diff --git a/sapi/cgi/cgi_main.c b/sapi/cgi/cgi_main.c
index fa9fbd3c3f..e51277c218 100644
--- a/sapi/cgi/cgi_main.c
+++ b/sapi/cgi/cgi_main.c
@@ -1739,9 +1739,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);
diff --git a/sapi/cgi/tests/apache_response_headers.phpt b/sapi/cgi/tests/apache_response_headers.phpt
new file mode 100644
index 0000000000..2964ac7bc7
--- /dev/null
+++ b/sapi/cgi/tests/apache_response_headers.phpt
@@ -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===