php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login

Patch Fix-segfault-after-two-multipart-form-data-POST-and-404-request for Built-in web server Bug #60477

Patch version 2011-12-09 04:08 UTC

Return to Bug #60477 | Download this patch
Patch Revisions:

Developer: reeze.xia@gmail.com

Index: main/SAPI.c
===================================================================
--- main/SAPI.c	(revision 320680)
+++ main/SAPI.c	(working copy)
@@ -533,6 +533,7 @@
 	}
 	if (SG(rfc1867_uploaded_files)) {
 		destroy_uploaded_files_hash(TSRMLS_C);
+		SG(rfc1867_uploaded_files) = NULL;
 	}
 	if (SG(sapi_headers).mimetype) {
 		efree(SG(sapi_headers).mimetype);
Index: sapi/cli/tests/php_cli_server_014.phpt
===================================================================
--- sapi/cli/tests/php_cli_server_014.phpt	(revision 0)
+++ sapi/cli/tests/php_cli_server_014.phpt	(revision 0)
@@ -0,0 +1,84 @@
+--TEST--
+Bug #60477: Segfault after two multipart/form-data POST requestes, one 200 RQ and one 404
+--SKIPIF--
+<?php
+include "skipif.inc"; 
+?>
+--FILE--
+<?php
+include "php_cli_server.inc";
+php_cli_server_start(NULL, TRUE);
+
+list($host, $port) = explode(':', PHP_CLI_SERVER_ADDRESS);
+$port = intval($port)?:80;
+$output = '';
+
+$fp = fsockopen($host, $port, $errno, $errstr, 0.5);
+if (!$fp) {
+  die("connect failed");
+}
+
+
+$script_name = "php_cli_server_014.tmp.php";
+
+// empty php file
+file_put_contents(__DIR__ . "/$script_name", '<?php echo "OK\n";'); 
+
+if(fwrite($fp, <<<HEADER
+POST /$script_name HTTP/1.1
+Host: {$host}
+Content-Type: multipart/form-data; boundary=---------123456789
+Content-Length: 70
+
+---------123456789
+Content-Type: application/x-www-form-urlencoded
+a=b
+HEADER
+)) {
+	while (!feof($fp)) {
+		$output .= fgets($fp);
+	}
+}
+
+fclose($fp);
+
+$fp = fsockopen($host, $port, $errno, $errstr, 0.5);
+if(fwrite($fp, <<<HEADER
+POST /main/foo/bar HTTP/1.1
+Host: {$host}
+Content-Type: multipart/form-data; boundary=---------123456789
+Content-Length: 70
+
+---------123456789
+Content-Type: application/x-www-form-urlencoded
+a=b
+HEADER
+)) {
+	while (!feof($fp)) {
+		$output .= fgets($fp);
+	}
+}
+
+echo preg_replace("/<style type=\"text\/css\">(.*?)<\/style>/s", "<style type=\"text/css\">AAA</style>", $output), "\n";
+fclose($fp);
+
+@unlink(__DIR__ . "/$script_name");
+?>
+--EXPECTF--
+
+HTTP/1.1 200 OK
+Host: %s
+Connection: closed
+X-Powered-By: %s
+Content-type: %s
+
+OK
+HTTP/1.1 404 Not Found
+Host: %s
+Connection: closed
+Content-Type: %s
+Content-Length: %d
+
+<html><head><title>404 Not Found</title><style type="text/css">AAA</style>
+</head><body><h1 class="h">Not Found</h1><p>The requested resource /main/foo/bar was not found on this server.</p></body></html>
+
 
PHP Copyright © 2001-2014 The PHP Group
All rights reserved.
Last updated: Thu Apr 17 16:02:22 2014 UTC