From: stodorovic Date: Tue, 2 Oct 2018 06:36:29 +0000 (+0200) Subject: Fix #76954: apache_response_headers removes last character from header name X-Git-Tag: php-7.1.24RC1~20 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=47b89bc5314534e4aab4a8d6cda0da9d079366f6;p=php Fix #76954: apache_response_headers removes last character from header name --- diff --git a/NEWS b/NEWS index d77f4ed465..dd8884ce43 100644 --- 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). 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-- + +--FILE-- + +'; + +file_put_contents( $test_file, $code ); + +passthru( "$php -n -q " . escapeshellarg( $test_file ) ); + +?> +===DONE=== +--CLEAN-- + +--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===