Skip to content

Commit 27ff425

Browse files
committed
Merge branch 'PHP-5.5' into PHP-5.6
* PHP-5.5: Handle NULL strings in sapi_cli_server_register_variable(). Allow CLI server test scripts to specify the name of the router file. Conflicts: sapi/cli/tests/php_cli_server.inc
2 parents 4756207 + 448ef30 commit 27ff425

File tree

9 files changed

+51
-10
lines changed

9 files changed

+51
-10
lines changed

NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@
2222
- CGI:
2323
. Fix bug #68618 (out of bounds read crashes php-cgi). (Stas)
2424

25+
- CLI server:
26+
. Fix bug #68745 (Invalid HTTP requests make web server segfault). (Adam)
27+
2528
- cURL:
2629
. Fixed bug #67643 (curl_multi_getcontent returns '' when
2730
CURLOPT_RETURNTRANSFER isn't set). (Jille Timmermans)

sapi/cli/php_cli_server.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -708,6 +708,11 @@ static void sapi_cli_server_register_variable(zval *track_vars_array, const char
708708
{
709709
char *new_val = (char *)val;
710710
uint new_val_len;
711+
712+
if (NULL == val) {
713+
return;
714+
}
715+
711716
if (sapi_module.input_filter(PARSE_SERVER, (char*)key, &new_val, strlen(val), &new_val_len TSRMLS_CC)) {
712717
php_register_variable_safe((char *)key, new_val, new_val_len, track_vars_array TSRMLS_CC);
713718
}

sapi/cli/tests/bug61977.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ include "skipif.inc";
77
--FILE--
88
<?php
99
include "php_cli_server.inc";
10-
php_cli_server_start('<?php ?>', true);
10+
php_cli_server_start('<?php ?>', null);
1111

1212
/*
1313
* If a Mime Type is added in php_cli_server.c, add it to this array and update

sapi/cli/tests/bug68745.phpt

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
--TEST--
2+
Bug #68745 (Invalid HTTP requests make web server segfault)
3+
--SKIPIF--
4+
<?php
5+
include "skipif.inc";
6+
?>
7+
--FILE--
8+
<?php
9+
include "php_cli_server.inc";
10+
php_cli_server_start('var_dump(count($_SERVER));', 'not-index.php');
11+
12+
list($host, $port) = explode(':', PHP_CLI_SERVER_ADDRESS);
13+
$port = intval($port)?:80;
14+
15+
$fp = fsockopen($host, $port, $errno, $errstr, 0.5);
16+
if (!$fp) {
17+
die("connect failed");
18+
}
19+
20+
if(fwrite($fp, "GET www.example.com:80 HTTP/1.1\r\n\r\n")) {
21+
while (!feof($fp)) {
22+
echo fgets($fp);
23+
}
24+
}
25+
26+
fclose($fp);
27+
?>
28+
--EXPECTF--
29+
HTTP/1.1 200 OK
30+
Connection: close
31+
X-Powered-By: %s
32+
Content-type: text/html; charset=UTF-8
33+
34+
int(%d)

sapi/cli/tests/php_cli_server.inc

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,12 @@ define ("PHP_CLI_SERVER_HOSTNAME", "localhost");
33
define ("PHP_CLI_SERVER_PORT", 8964);
44
define ("PHP_CLI_SERVER_ADDRESS", PHP_CLI_SERVER_HOSTNAME.":".PHP_CLI_SERVER_PORT);
55

6-
function php_cli_server_start($code = 'echo "Hello world";', $no_router = FALSE, $cmd_args = null) {
6+
function php_cli_server_start($code = 'echo "Hello world";', $router = 'index.php', $cmd_args = null) {
77
$php_executable = getenv('TEST_PHP_EXECUTABLE');
88
$doc_root = __DIR__;
9-
$router = "index.php";
109

1110
if ($code) {
12-
file_put_contents($doc_root . '/' . $router, '<?php ' . $code . ' ?>');
11+
file_put_contents($doc_root . '/' . ($router ?: 'index.php'), '<?php ' . $code . ' ?>');
1312
}
1413

1514
$descriptorspec = array(
@@ -20,14 +19,14 @@ function php_cli_server_start($code = 'echo "Hello world";', $no_router = FALSE,
2019

2120
if (substr(PHP_OS, 0, 3) == 'WIN') {
2221
$cmd = "{$php_executable} -t {$doc_root} -n {$cmd_args} -S " . PHP_CLI_SERVER_ADDRESS;
23-
if (!$no_router) {
22+
if (!is_null($router)) {
2423
$cmd .= " {$router}";
2524
}
2625

2726
$handle = proc_open(addslashes($cmd), $descriptorspec, $pipes, $doc_root, NULL, array("bypass_shell" => true, "suppress_errors" => true));
2827
} else {
2928
$cmd = "exec {$php_executable} -t {$doc_root} -n {$cmd_args} -S " . PHP_CLI_SERVER_ADDRESS;
30-
if (!$no_router) {
29+
if (!is_null($router)) {
3130
$cmd .= " {$router}";
3231
}
3332
$cmd .= " 2>/dev/null";

sapi/cli/tests/php_cli_server_009.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ include "skipif.inc";
1010
--FILE--
1111
<?php
1212
include "php_cli_server.inc";
13-
php_cli_server_start('var_dump($_SERVER["PATH_INFO"]);', TRUE);
13+
php_cli_server_start('var_dump($_SERVER["PATH_INFO"]);', null);
1414

1515
list($host, $port) = explode(':', PHP_CLI_SERVER_ADDRESS);
1616
$port = intval($port)?:80;

sapi/cli/tests/php_cli_server_010.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ include "skipif.inc";
77
--FILE--
88
<?php
99
include "php_cli_server.inc";
10-
php_cli_server_start('var_dump($_SERVER["PHP_SELF"], $_SERVER["SCRIPT_NAME"], $_SERVER["PATH_INFO"], $_SERVER["QUERY_STRING"]);', TRUE);
10+
php_cli_server_start('var_dump($_SERVER["PHP_SELF"], $_SERVER["SCRIPT_NAME"], $_SERVER["PATH_INFO"], $_SERVER["QUERY_STRING"]);', null);
1111

1212
list($host, $port) = explode(':', PHP_CLI_SERVER_ADDRESS);
1313
$port = intval($port)?:80;

sapi/cli/tests/php_cli_server_013.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ include "skipif.inc";
77
--FILE--
88
<?php
99
include "php_cli_server.inc";
10-
php_cli_server_start(NULL, TRUE);
10+
php_cli_server_start(NULL, NULL);
1111

1212
list($host, $port) = explode(':', PHP_CLI_SERVER_ADDRESS);
1313
$port = intval($port)?:80;

sapi/cli/tests/php_cli_server_014.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ include "skipif.inc";
77
--FILE--
88
<?php
99
include "php_cli_server.inc";
10-
php_cli_server_start('echo done, "\n";', TRUE);
10+
php_cli_server_start('echo done, "\n";', null);
1111

1212
list($host, $port) = explode(':', PHP_CLI_SERVER_ADDRESS);
1313
$port = intval($port)?:80;

0 commit comments

Comments
 (0)