Skip to content

Commit 45a3f4c

Browse files
committed
Merge branch 'PHP-8.1'
* PHP-8.1: Fix GH-9316: $http_response_header is wrong for long status line
2 parents cb5d5d8 + 5d196d9 commit 45a3f4c

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

ext/standard/http_fopen_wrapper.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -713,6 +713,10 @@ static php_stream *php_stream_url_wrap_http_ex(php_stream_wrapper *wrapper,
713713
if (tmp_line_len >= 1 &&tmp_line[tmp_line_len - 1] == '\r') {
714714
--tmp_line_len;
715715
}
716+
} else {
717+
// read and discard rest of status line
718+
char *line = php_stream_get_line(stream, NULL, 0, NULL);
719+
efree(line);
716720
}
717721
ZVAL_STRINGL(&http_response, tmp_line, tmp_line_len);
718722
zend_hash_next_index_insert(Z_ARRVAL_P(response_header), &http_response);

ext/standard/tests/http/gh9316.phpt

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
--TEST--
2+
Bug GH-9316 ($http_response_header is wrong for long status line)
3+
--SKIPIF--
4+
<?php require 'server.inc'; http_server_skipif(); ?>
5+
--INI--
6+
allow_url_fopen=1
7+
--FILE--
8+
<?php
9+
require 'server.inc';
10+
11+
$responses = array(
12+
"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",
13+
"data://text/plain,HTTP/1.1 200 \r\nGood: Header\r\n\r\nBody",
14+
);
15+
16+
['pid' => $pid, 'uri' => $uri] = http_server($responses, $output);
17+
18+
for ($i = 0; $i < count($responses); ++$i) {
19+
$f = @fopen($uri, "r");
20+
var_dump($http_response_header);
21+
fclose($f);
22+
}
23+
24+
http_server_kill($pid);
25+
26+
--EXPECT--
27+
array(2) {
28+
[0]=>
29+
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 "
30+
[1]=>
31+
string(12) "Good: Header"
32+
}
33+
array(2) {
34+
[0]=>
35+
string(13) "HTTP/1.1 200 "
36+
[1]=>
37+
string(12) "Good: Header"
38+
}

0 commit comments

Comments
 (0)