1--TEST--
2Bug #60477: Segfault after two multipart/form-data POST requestes
3--SKIPIF--
4<?php
5include "skipif.inc";
6?>
7--FILE--
8<?php
9include "php_cli_server.inc";
10php_cli_server_start('echo "done\n";', null);
11
12$output = '';
13$host = PHP_CLI_SERVER_HOSTNAME;
14$fp = php_cli_server_connect();
15
16if(fwrite($fp, <<<HEADER
17POST /index.php HTTP/1.1
18Host: {$host}
19Content-Type: multipart/form-data; boundary=---------123456789
20Content-Length: 70
21
22---------123456789
23Content-Type: application/x-www-form-urlencoded
24a=b
25HEADER
26)) {
27    while (!feof($fp)) {
28        $output .= fgets($fp);
29    }
30}
31
32fclose($fp);
33
34$fp = php_cli_server_connect();
35if(fwrite($fp, <<<HEADER
36POST /main/no-exists.php HTTP/1.1
37Host: {$host}
38Content-Type: multipart/form-data; boundary=---------123456789
39Content-Length: 70
40
41---------123456789
42Content-Type: application/x-www-form-urlencoded
43a=b
44HEADER
45)) {
46    while (!feof($fp)) {
47        $output .= fgets($fp);
48    }
49}
50
51echo preg_replace("/<style>(.*?)<\/style>/s", "<style>AAA</style>", $output), "\n";
52fclose($fp);
53
54?>
55--EXPECTF--
56HTTP/1.1 200 OK
57Host: %s
58Date: %s
59Connection: close
60X-Powered-By: %s
61Content-type: %s
62
63done
64HTTP/1.1 404 Not Found
65Host: %s
66Date: %s
67Connection: close
68Content-Type: %s
69Content-Length: %d
70
71<!doctype html><html><head><title>404 Not Found</title><style>AAA</style>
72</head><body><h1>Not Found</h1><p>The requested resource <code class="url">/main/no-exists.php</code> was not found on this server.</p></body></html>
73