Skip to content

Commit 90b2440

Browse files
committed
Merge branch 'PHP-7.4' into PHP-8.0
* PHP-7.4: Fix #78719: http wrapper silently ignores long Location headers
2 parents 957cb13 + 51e2015 commit 90b2440

File tree

3 files changed

+33
-13
lines changed

3 files changed

+33
-13
lines changed

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ PHP NEWS
2424

2525
- Standard:
2626
. Fixed bug #80771 (phpinfo(INFO_CREDITS) displays nothing in CLI). (cmb)
27+
. Fixed bug #78719 (http wrapper silently ignores long Location headers).
28+
(cmb)
2729

2830
18 Feb 2021, PHP 8.0.3
2931

ext/standard/http_fopen_wrapper.c

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -730,24 +730,16 @@ static php_stream *php_stream_url_wrap_http_ex(php_stream_wrapper *wrapper,
730730

731731
/* read past HTTP headers */
732732

733-
http_header_line = emalloc(HTTP_HEADER_BLOCK_SIZE);
734-
735733
while (!php_stream_eof(stream)) {
736734
size_t http_header_line_length;
737735

738-
if (php_stream_get_line(stream, http_header_line, HTTP_HEADER_BLOCK_SIZE, &http_header_line_length) && *http_header_line != '\n' && *http_header_line != '\r') {
736+
if (http_header_line != NULL) {
737+
efree(http_header_line);
738+
}
739+
if ((http_header_line = php_stream_get_line(stream, NULL, 0, &http_header_line_length)) && *http_header_line != '\n' && *http_header_line != '\r') {
739740
char *e = http_header_line + http_header_line_length - 1;
740741
char *http_header_value;
741-
if (*e != '\n') {
742-
do { /* partial header */
743-
if (php_stream_get_line(stream, http_header_line, HTTP_HEADER_BLOCK_SIZE, &http_header_line_length) == NULL) {
744-
php_stream_wrapper_log_error(wrapper, options, "Failed to read HTTP headers");
745-
goto out;
746-
}
747-
e = http_header_line + http_header_line_length - 1;
748-
} while (*e != '\n');
749-
continue;
750-
}
742+
751743
while (e >= http_header_line && (*e == '\n' || *e == '\r')) {
752744
e--;
753745
}

ext/standard/tests/http/bug78719.phpt

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
--TEST--
2+
Bug #78719 (http wrapper silently ignores long Location headers)
3+
--SKIPIF--
4+
<?php require 'server.inc'; http_server_skipif('tcp://127.0.0.1:12342'); ?>
5+
--INI--
6+
allow_url_fopen=1
7+
--FILE--
8+
<?php
9+
require 'server.inc';
10+
11+
$url = str_repeat('*', 2000);
12+
$responses = array(
13+
"data://text/plain,HTTP/1.0 302 Ok\r\nLocation: $url\r\n\r\nBody",
14+
);
15+
$pid = http_server("tcp://127.0.0.1:12342", $responses, $output);
16+
17+
$context = stream_context_create(['http' => ['follow_location' => 0]]);
18+
$stream = fopen('http://127.0.0.1:12342/', 'r', false, $context);
19+
var_dump(stream_get_contents($stream));
20+
var_dump(stream_get_meta_data($stream)['wrapper_data'][1] === "Location: $url");
21+
22+
http_server_kill($pid);
23+
?>
24+
--EXPECTF--
25+
string(4) "Body"
26+
bool(true)

0 commit comments

Comments
 (0)