--- /dev/null
-Content-type: text/html
+ --TEST--
+ Bug #68745 (Invalid HTTP requests make web server segfault)
+ --SKIPIF--
+ <?php
+ include "skipif.inc";
+ ?>
+ --FILE--
+ <?php
+ include "php_cli_server.inc";
+ php_cli_server_start('var_dump(count($_SERVER));', 'not-index.php');
+
+ list($host, $port) = explode(':', PHP_CLI_SERVER_ADDRESS);
+ $port = intval($port)?:80;
+
+ $fp = fsockopen($host, $port, $errno, $errstr, 0.5);
+ if (!$fp) {
+ die("connect failed");
+ }
+
+ if(fwrite($fp, "GET www.example.com:80 HTTP/1.1\r\n\r\n")) {
+ while (!feof($fp)) {
+ echo fgets($fp);
+ }
+ }
+
+ fclose($fp);
+ ?>
+ --EXPECTF--
+ HTTP/1.1 200 OK
+ Connection: close
+ X-Powered-By: %s
++Content-type: text/html; charset=UTF-8
+
+ int(%d)
define ("PHP_CLI_SERVER_PORT", 8964);
define ("PHP_CLI_SERVER_ADDRESS", PHP_CLI_SERVER_HOSTNAME.":".PHP_CLI_SERVER_PORT);
- function php_cli_server_start($code = 'echo "Hello world";', $no_router = FALSE, $cmd_args = null) {
-function php_cli_server_start($code = 'echo "Hello world";', $router = 'index.php') {
++function php_cli_server_start($code = 'echo "Hello world";', $router = 'index.php', $cmd_args = null) {
$php_executable = getenv('TEST_PHP_EXECUTABLE');
$doc_root = __DIR__;
- $router = "index.php";
if ($code) {
- file_put_contents($doc_root . '/' . $router, '<?php ' . $code . ' ?>');
+ file_put_contents($doc_root . '/' . ($router ?: 'index.php'), '<?php ' . $code . ' ?>');
}
$descriptorspec = array(
);
if (substr(PHP_OS, 0, 3) == 'WIN') {
- $cmd = "{$php_executable} -t {$doc_root} -n -S " . PHP_CLI_SERVER_ADDRESS;
+ $cmd = "{$php_executable} -t {$doc_root} -n {$cmd_args} -S " . PHP_CLI_SERVER_ADDRESS;
- if (!$no_router) {
+ if (!is_null($router)) {
$cmd .= " {$router}";
}
$handle = proc_open(addslashes($cmd), $descriptorspec, $pipes, $doc_root, NULL, array("bypass_shell" => true, "suppress_errors" => true));
} else {
- $cmd = "exec {$php_executable} -t {$doc_root} -n -S " . PHP_CLI_SERVER_ADDRESS;
+ $cmd = "exec {$php_executable} -t {$doc_root} -n {$cmd_args} -S " . PHP_CLI_SERVER_ADDRESS;
- if (!$no_router) {
+ if (!is_null($router)) {
$cmd .= " {$router}";
}
$cmd .= " 2>/dev/null";