Skip to content

Fix GH-9316: $http_response_header is wrong for long status line #9319

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions ext/standard/http_fopen_wrapper.c
Original file line number Diff line number Diff line change
Expand Up @@ -717,6 +717,10 @@ static php_stream *php_stream_url_wrap_http_ex(php_stream_wrapper *wrapper,
if (tmp_line_len >= 1 &&tmp_line[tmp_line_len - 1] == '\r') {
--tmp_line_len;
}
} else {
// read and discard rest of status line
char *line = php_stream_get_line(stream, NULL, 0, NULL);
efree(line);
}
ZVAL_STRINGL(&http_response, tmp_line, tmp_line_len);
zend_hash_next_index_insert(Z_ARRVAL_P(response_header), &http_response);
Expand Down
38 changes: 38 additions & 0 deletions ext/standard/tests/http/gh9316.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
--TEST--
Bug GH-9316 ($http_response_header is wrong for long status line)
--SKIPIF--
<?php require 'server.inc'; http_server_skipif(); ?>
--INI--
allow_url_fopen=1
--FILE--
<?php
require 'server.inc';

$responses = array(
"data://text/plain,HTTP/1.1 200 Some very long reason-phrase to test that this is properly handled by our code without adding a new header like Bad: Header\r\nGood: Header\r\n\r\nBody",
"data://text/plain,HTTP/1.1 200 \r\nGood: Header\r\n\r\nBody",
);

['pid' => $pid, 'uri' => $uri] = http_server($responses, $output);

for ($i = 0; $i < count($responses); ++$i) {
$f = @fopen($uri, "r");
var_dump($http_response_header);
fclose($f);
}

http_server_kill($pid);

--EXPECT--
array(2) {
[0]=>
string(126) "HTTP/1.1 200 Some very long reason-phrase to test that this is properly handled by our code without adding a new header like "
[1]=>
string(12) "Good: Header"
}
array(2) {
[0]=>
string(13) "HTTP/1.1 200 "
[1]=>
string(12) "Good: Header"
}