Skip to content

Commit ec5b87c

Browse files
committed
Merge branch 'PHP-5.5' of https://git.php.net/repository/php-src into PHP-5.5
# By Michael Wallner (2) and Dmitry Stogov (1) # Via Michael Wallner (3) and Christopher Jones (1) * 'PHP-5.5' of https://git.php.net/repository/php-src: fix bug #62396 'make test' crashes starting with 5.3.14 (missing gzencode()) Fixed bug #61548 Reverted patch (it was used for internal testing and was committed by accident)
2 parents aeb6e9c + 4b61203 commit ec5b87c

File tree

4 files changed

+165
-53
lines changed

4 files changed

+165
-53
lines changed

ext/standard/http_fopen_wrapper.c

Lines changed: 31 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,30 @@
8484
#define HTTP_WRAPPER_HEADER_INIT 1
8585
#define HTTP_WRAPPER_REDIRECTED 2
8686

87+
static inline void strip_header(char *header_bag, char *lc_header_bag,
88+
const char *lc_header_name)
89+
{
90+
char *lc_header_start = strstr(lc_header_bag, lc_header_name);
91+
char *header_start = header_bag + (lc_header_start - lc_header_bag);
92+
93+
if (lc_header_start
94+
&& (lc_header_start == lc_header_bag || *(lc_header_start-1) == '\n')
95+
) {
96+
char *lc_eol = strchr(lc_header_start, '\n');
97+
char *eol = header_start + (lc_eol - lc_header_start);
98+
99+
if (lc_eol) {
100+
size_t eollen = strlen(lc_eol);
101+
102+
memmove(lc_header_start, lc_eol+1, eollen);
103+
memmove(header_start, eol+1, eollen);
104+
} else {
105+
*lc_header_start = '\0';
106+
*header_start = '\0';
107+
}
108+
}
109+
}
110+
87111
php_stream *php_stream_url_wrap_http_ex(php_stream_wrapper *wrapper, char *path, char *mode, int options, char **opened_path, php_stream_context *context, int redirect_max, int flags STREAMS_DC TSRMLS_DC) /* {{{ */
88112
{
89113
php_stream *stream = NULL;
@@ -425,40 +449,17 @@ php_stream *php_stream_url_wrap_http_ex(php_stream_wrapper *wrapper, char *path,
425449
if (tmp && strlen(tmp) > 0) {
426450
char *s;
427451

428-
if (!header_init) { /* Remove post headers for redirects */
429-
int l = strlen(tmp);
430-
char *s2, *tmp_c = estrdup(tmp);
431-
432-
php_strtolower(tmp_c, l);
433-
if ((s = strstr(tmp_c, "content-length:"))) {
434-
if ((s2 = memchr(s, '\n', tmp_c + l - s))) {
435-
int b = tmp_c + l - 1 - s2;
436-
memmove(tmp, tmp + (s2 + 1 - tmp_c), b);
437-
memmove(tmp_c, s2 + 1, b);
438-
439-
} else {
440-
tmp[s - tmp_c] = *s = '\0';
441-
}
442-
l = strlen(tmp_c);
443-
}
444-
if ((s = strstr(tmp_c, "content-type:"))) {
445-
if ((s2 = memchr(s, '\n', tmp_c + l - s))) {
446-
memmove(tmp, tmp + (s2 + 1 - tmp_c), tmp_c + l - 1 - s2);
447-
} else {
448-
tmp[s - tmp_c] = '\0';
449-
}
450-
}
451-
452-
efree(tmp_c);
453-
tmp_c = php_trim(tmp, strlen(tmp), NULL, 0, NULL, 3 TSRMLS_CC);
454-
efree(tmp);
455-
tmp = tmp_c;
456-
}
457-
458452
user_headers = estrdup(tmp);
459453

460454
/* Make lowercase for easy comparison against 'standard' headers */
461455
php_strtolower(tmp, strlen(tmp));
456+
457+
if (!header_init) {
458+
/* strip POST headers on redirect */
459+
strip_header(user_headers, tmp, "content-length:");
460+
strip_header(user_headers, tmp, "content-type:");
461+
}
462+
462463
if ((s = strstr(tmp, "user-agent:")) &&
463464
(s == tmp || *(s-1) == '\r' || *(s-1) == '\n' ||
464465
*(s-1) == '\t' || *(s-1) == ' ')) {

ext/standard/tests/http/bug61548.phpt

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
--TEST--
2+
Bug #61548 (content-type must appear at the end of headers)
3+
--INI--
4+
allow_url_fopen=1
5+
--SKIPIF--
6+
<?php require 'server.inc'; http_server_skipif('tcp://127.0.0.1:12342'); ?>
7+
--FILE--
8+
<?php
9+
require 'server.inc';
10+
11+
function do_test($header) {
12+
$options = [
13+
'http' => [
14+
'method' => 'POST',
15+
'header' => $header,
16+
'follow_location' => true,
17+
],
18+
];
19+
20+
$ctx = stream_context_create($options);
21+
22+
$responses = [
23+
"data://text/plain,HTTP/1.1 201\r\nLocation: /foo\r\n\r\n",
24+
"data://text/plain,HTTP/1.1 200\r\nConnection: close\r\n\r\n",
25+
];
26+
$pid = http_server('tcp://127.0.0.1:12342', $responses, $output);
27+
28+
$fd = fopen('http://127.0.0.1:12342/', 'rb', false, $ctx);
29+
fseek($output, 0, SEEK_SET);
30+
echo stream_get_contents($output);
31+
32+
http_server_kill($pid);
33+
}
34+
35+
do_test("First:1\nSecond:2\nContent-type: text/plain");
36+
do_test("First:1\nSecond:2\nContent-type: text/plain\n");
37+
do_test("First:1\nSecond:2\nContent-type: text/plain\nThird:");
38+
do_test("First:1\nContent-type:text/plain\nSecond:2");
39+
do_test("First:1\nContent-type:text/plain\nSecond:2\n");
40+
do_test("First:1\nContent-type:text/plain\nSecond:2\nThird:");
41+
42+
?>
43+
Done
44+
--EXPECT--
45+
POST / HTTP/1.0
46+
Host: 127.0.0.1:12342
47+
First:1
48+
Second:2
49+
Content-type: text/plain
50+
51+
GET /foo HTTP/1.0
52+
Host: 127.0.0.1:12342
53+
First:1
54+
Second:2
55+
56+
57+
POST / HTTP/1.0
58+
Host: 127.0.0.1:12342
59+
First:1
60+
Second:2
61+
Content-type: text/plain
62+
63+
GET /foo HTTP/1.0
64+
Host: 127.0.0.1:12342
65+
First:1
66+
Second:2
67+
68+
69+
POST / HTTP/1.0
70+
Host: 127.0.0.1:12342
71+
First:1
72+
Second:2
73+
Content-type: text/plain
74+
Third:
75+
76+
GET /foo HTTP/1.0
77+
Host: 127.0.0.1:12342
78+
First:1
79+
Second:2
80+
Third:
81+
82+
POST / HTTP/1.0
83+
Host: 127.0.0.1:12342
84+
First:1
85+
Content-type:text/plain
86+
Second:2
87+
88+
GET /foo HTTP/1.0
89+
Host: 127.0.0.1:12342
90+
First:1
91+
Second:2
92+
93+
POST / HTTP/1.0
94+
Host: 127.0.0.1:12342
95+
First:1
96+
Content-type:text/plain
97+
Second:2
98+
99+
GET /foo HTTP/1.0
100+
Host: 127.0.0.1:12342
101+
First:1
102+
Second:2
103+
104+
POST / HTTP/1.0
105+
Host: 127.0.0.1:12342
106+
First:1
107+
Content-type:text/plain
108+
Second:2
109+
Third:
110+
111+
GET /foo HTTP/1.0
112+
Host: 127.0.0.1:12342
113+
First:1
114+
Second:2
115+
Third:
116+
117+
Done
118+

run-tests.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,7 @@ function save_or_mail_results()
459459
$compression = 0;
460460
$output_file = $CUR_DIR . '/php_test_results_' . date('Ymd_Hi') . '.txt';
461461

462-
if ($compression) {
462+
if ($compression && in_array("compress.zlib", stream_get_filters())) {
463463
$output_file = 'compress.zlib://' . $output_file . '.gz';
464464
}
465465

@@ -1547,6 +1547,16 @@ function run_test($php, $file, $env)
15471547
}
15481548
}
15491549
}
1550+
1551+
if (!extension_loaded("zlib")
1552+
&& ( array_key_exists("GZIP_POST", $section_text)
1553+
|| array_key_exists("DEFLATE_POST", $section_text))
1554+
) {
1555+
$message = "ext/zlib required";
1556+
show_result('SKIP', $tested, $tested_file, "reason: $message", $temp_filenames);
1557+
junit_mark_test_as('SKIP', $shortname, $tested, null, "<![CDATA[\n$message\n]]>");
1558+
return 'SKIPPED';
1559+
}
15501560

15511561
if (@count($section_text['REDIRECTTEST']) == 1) {
15521562
$test_files = array();

sapi/cgi/cgi_main.c

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,6 @@ static const opt_struct OPTIONS[] = {
154154
{'?', 0, "usage"},/* help alias (both '?' and 'usage') */
155155
{'v', 0, "version"},
156156
{'z', 1, "zend-extension"},
157-
{'W', 1, "warmup"},
158157
{'T', 1, "timing"},
159158
{'-', 0, NULL} /* end of args */
160159
};
@@ -1755,7 +1754,6 @@ int main(int argc, char *argv[])
17551754
int fcgi_fd = 0;
17561755
fcgi_request *request = NULL;
17571756
int repeats = 1;
1758-
int warmup_repeats = 0;
17591757
int benchmark = 0;
17601758
#if HAVE_GETTIMEOFDAY
17611759
struct timeval start, end;
@@ -2105,9 +2103,6 @@ consult the installation file that came with this distribution, or visit \n\
21052103
time(&start);
21062104
#endif
21072105
break;
2108-
case 'W':
2109-
warmup_repeats = atoi(php_optarg);
2110-
break;
21112106
case 'h':
21122107
case '?':
21132108
if (request) {
@@ -2521,24 +2516,12 @@ consult the installation file that came with this distribution, or visit \n\
25212516

25222517
if (!fastcgi) {
25232518
if (benchmark) {
2524-
if (warmup_repeats) {
2525-
warmup_repeats--;
2526-
if (!warmup_repeats) {
2527-
#ifdef HAVE_GETTIMEOFDAY
2528-
gettimeofday(&start, NULL);
2529-
#else
2530-
time(&start);
2531-
#endif
2532-
}
2519+
repeats--;
2520+
if (repeats > 0) {
2521+
script_file = NULL;
2522+
php_optind = orig_optind;
2523+
php_optarg = orig_optarg;
25332524
continue;
2534-
} else {
2535-
repeats--;
2536-
if (repeats > 0) {
2537-
script_file = NULL;
2538-
php_optind = orig_optind;
2539-
php_optarg = orig_optarg;
2540-
continue;
2541-
}
25422525
}
25432526
}
25442527
break;

0 commit comments

Comments
 (0)