diff options
author | stodorovic <sasa.todorovic@gmx.com> | 2018-10-02 08:36:29 +0200 |
---|---|---|
committer | Christoph M. Becker <cmbecker69@gmx.de> | 2018-10-08 12:29:31 +0200 |
commit | 47b89bc5314534e4aab4a8d6cda0da9d079366f6 (patch) | |
tree | 24a5ff84641860a1b767e34c0889d49a441ae1de /sapi/cgi | |
parent | c097acd52e89a3b1d0cb6a181bb4650be9625b6c (diff) | |
download | php-git-47b89bc5314534e4aab4a8d6cda0da9d079366f6.tar.gz |
Fix #76954: apache_response_headers removes last character from header name
Diffstat (limited to 'sapi/cgi')
-rw-r--r-- | sapi/cgi/cgi_main.c | 4 | ||||
-rw-r--r-- | sapi/cgi/tests/apache_response_headers.phpt | 48 |
2 files changed, 50 insertions, 2 deletions
diff --git a/sapi/cgi/cgi_main.c b/sapi/cgi/cgi_main.c index fda24290fc..56f0c5b9e8 100644 --- a/sapi/cgi/cgi_main.c +++ b/sapi/cgi/cgi_main.c @@ -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 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=== |