From 47b89bc5314534e4aab4a8d6cda0da9d079366f6 Mon Sep 17 00:00:00 2001 From: stodorovic Date: Tue, 2 Oct 2018 08:36:29 +0200 Subject: [PATCH] Fix #76954: apache_response_headers removes last character from header name --- NEWS | 2 + sapi/cgi/cgi_main.c | 4 +- sapi/cgi/tests/apache_response_headers.phpt | 48 +++++++++++++++++++++ 3 files changed, 52 insertions(+), 2 deletions(-) create mode 100644 sapi/cgi/tests/apache_response_headers.phpt diff --git a/NEWS b/NEWS index d77f4ed4656..dd8884ce433 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 fda24290fc7..56f0c5b9e85 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 00000000000..2964ac7bc71 --- /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===