]> granicus.if.org Git - php/commitdiff
Fix #76954: apache_response_headers removes last character from header name
authorstodorovic <sasa.todorovic@gmx.com>
Tue, 2 Oct 2018 06:36:29 +0000 (08:36 +0200)
committerChristoph M. Becker <cmbecker69@gmx.de>
Mon, 8 Oct 2018 10:29:31 +0000 (12:29 +0200)
NEWS
sapi/cgi/cgi_main.c
sapi/cgi/tests/apache_response_headers.phpt [new file with mode: 0644]

diff --git a/NEWS b/NEWS
index d77f4ed4656b8e1046573dfe832d1a892ed87f75..dd8884ce433ab4f9f7733d2fc3f902894bf13233 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -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).
index fda24290fc7a41891e959cf71924249c5d190a7f..56f0c5b9e8574e99696c7bd3e50b5d2b7f689677 100644 (file)
@@ -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);
diff --git a/sapi/cgi/tests/apache_response_headers.phpt b/sapi/cgi/tests/apache_response_headers.phpt
new file mode 100644 (file)
index 0000000..2964ac7
--- /dev/null
@@ -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===