laruence                                 Fri, 09 Dec 2011 05:37:41 +0000

Revision: http://svn.php.net/viewvc?view=revision&revision=320716

Log:
Fixed bug #60477 (Segfault after two multipart/form-data POST requests)

Bug: https://bugs.php.net/60477 (Assigned) Segfault after two 
multipart/form-data POST requestes, one 200 RQ and one 404
      
Changed paths:
    U   php/php-src/branches/PHP_5_4/NEWS
    U   php/php-src/branches/PHP_5_4/sapi/cli/php_cli_server.c
    A   php/php-src/branches/PHP_5_4/sapi/cli/tests/php_cli_server_014.phpt
    U   php/php-src/trunk/sapi/cli/php_cli_server.c
    A   php/php-src/trunk/sapi/cli/tests/php_cli_server_014.phpt

Modified: php/php-src/branches/PHP_5_4/NEWS
===================================================================
--- php/php-src/branches/PHP_5_4/NEWS   2011-12-09 05:25:05 UTC (rev 320715)
+++ php/php-src/branches/PHP_5_4/NEWS   2011-12-09 05:37:41 UTC (rev 320716)
@@ -1,6 +1,9 @@
 PHP                                                                        NEWS
 |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
 ?? Dec 2011, PHP 5.4.0 RC4
+- CLI SAPI:
+  . Fixed bug #60477 (Segfault after two multipart/form-data POST requests).
+    (Laruence)

 08 Dec 2011, PHP 5.4.0 RC3
 - Core:

Modified: php/php-src/branches/PHP_5_4/sapi/cli/php_cli_server.c
===================================================================
--- php/php-src/branches/PHP_5_4/sapi/cli/php_cli_server.c      2011-12-09 
05:25:05 UTC (rev 320715)
+++ php/php-src/branches/PHP_5_4/sapi/cli/php_cli_server.c      2011-12-09 
05:37:41 UTC (rev 320716)
@@ -1921,6 +1921,7 @@
        php_cli_server_close_connection(server, client TSRMLS_CC);
        destroy_request_info(&SG(request_info));
        SG(server_context) = NULL;
+       SG(rfc1867_uploaded_files) = NULL;
        return SUCCESS;
 }
 /* }}} */

Added: php/php-src/branches/PHP_5_4/sapi/cli/tests/php_cli_server_014.phpt
===================================================================
--- php/php-src/branches/PHP_5_4/sapi/cli/tests/php_cli_server_014.phpt         
                (rev 0)
+++ php/php-src/branches/PHP_5_4/sapi/cli/tests/php_cli_server_014.phpt 
2011-12-09 05:37:41 UTC (rev 320716)
@@ -0,0 +1,76 @@
+--TEST--
+Bug #60477: Segfault after two multipart/form-data POST requestes
+--SKIPIF--
+<?php
+include "skipif.inc";
+?>
+--FILE--
+<?php
+include "php_cli_server.inc";
+php_cli_server_start('echo done, "\n";', 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");
+}
+
+if(fwrite($fp, <<<HEADER
+POST /index.php 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/no-exists.php 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);
+
+?>
+--EXPECTF--
+
+HTTP/1.1 200 OK
+Host: %s
+Connection: closed
+X-Powered-By: %s
+Content-type: %s
+
+done
+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/no-exists.php was not found on this server.</p></body></html>

Modified: php/php-src/trunk/sapi/cli/php_cli_server.c
===================================================================
--- php/php-src/trunk/sapi/cli/php_cli_server.c 2011-12-09 05:25:05 UTC (rev 
320715)
+++ php/php-src/trunk/sapi/cli/php_cli_server.c 2011-12-09 05:37:41 UTC (rev 
320716)
@@ -1921,6 +1921,7 @@
        php_cli_server_close_connection(server, client TSRMLS_CC);
        destroy_request_info(&SG(request_info));
        SG(server_context) = NULL;
+       SG(rfc1867_uploaded_files) = NULL;
        return SUCCESS;
 }
 /* }}} */

Added: php/php-src/trunk/sapi/cli/tests/php_cli_server_014.phpt
===================================================================
--- php/php-src/trunk/sapi/cli/tests/php_cli_server_014.phpt                    
        (rev 0)
+++ php/php-src/trunk/sapi/cli/tests/php_cli_server_014.phpt    2011-12-09 
05:37:41 UTC (rev 320716)
@@ -0,0 +1,76 @@
+--TEST--
+Bug #60477: Segfault after two multipart/form-data POST requestes
+--SKIPIF--
+<?php
+include "skipif.inc";
+?>
+--FILE--
+<?php
+include "php_cli_server.inc";
+php_cli_server_start('echo done, "\n";', 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");
+}
+
+if(fwrite($fp, <<<HEADER
+POST /index.php 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/no-exists.php 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);
+
+?>
+--EXPECTF--
+
+HTTP/1.1 200 OK
+Host: %s
+Connection: closed
+X-Powered-By: %s
+Content-type: %s
+
+done
+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/no-exists.php was not found on this server.</p></body></html>

-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to