Skip to content

Commit 91bad92

Browse files
committed
Fix bug #71005 (Segfault in php_cli_server_dispatch_router()).
We didn't initialise the retval variable in php_cli_server_dispatch_router(); let's now initialise it to be IS_UNDEF, as the following if condition expects.
1 parent ed4b887 commit 91bad92

File tree

3 files changed

+51
-0
lines changed

3 files changed

+51
-0
lines changed

NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ PHP NEWS
2424
. Fixed exception not being thrown immediately into a generator yielding
2525
from an array. (Bob)
2626

27+
- CLI server:
28+
. Fixed bug #71005 (Segfault in php_cli_server_dispatch_router()). (Adam)
29+
2730
- Mysqlnd:
2831
. Fixed bug #68077 (LOAD DATA LOCAL INFILE / open_basedir restriction).
2932
(Laruence)

sapi/cli/php_cli_server.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2050,6 +2050,8 @@ static int php_cli_server_dispatch_router(php_cli_server *server, php_cli_server
20502050

20512051
zend_try {
20522052
zval retval;
2053+
2054+
ZVAL_UNDEF(&retval);
20532055
if (SUCCESS == zend_execute_scripts(ZEND_REQUIRE, &retval, 1, &zfd)) {
20542056
if (Z_TYPE(retval) != IS_UNDEF) {
20552057
decline = Z_TYPE(retval) == IS_FALSE;

sapi/cli/tests/bug71005.phpt

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
--TEST--
2+
Bug #71005 (Segfault in php_cli_server_dispatch_router())
3+
--SKIPIF--
4+
<?php
5+
include "skipif.inc";
6+
?>
7+
--FILE--
8+
<?php
9+
10+
$code = <<<'EOF'
11+
set_exception_handler(function () { echo 'goodbye'; });
12+
throw new Exception;
13+
EOF;
14+
15+
include "php_cli_server.inc";
16+
php_cli_server_start($code);
17+
18+
list($host, $port) = explode(':', PHP_CLI_SERVER_ADDRESS);
19+
$port = intval($port) ?: 80;
20+
21+
$fp = fsockopen($host, $port, $errno, $errstr, 0.5);
22+
if (!$fp) {
23+
die("connect failed");
24+
}
25+
26+
if(fwrite($fp, <<<HEADER
27+
GET / HTTP/1.1
28+
Host: {$host}
29+
30+
31+
HEADER
32+
)) {
33+
while (!feof($fp)) {
34+
echo fgets($fp);
35+
}
36+
}
37+
38+
?>
39+
--EXPECTF--
40+
HTTP/1.1 200 OK
41+
Host: %s
42+
Connection: close
43+
X-Powered-By: PHP/%s
44+
Content-type: text/html; charset=UTF-8
45+
46+
goodbye

0 commit comments

Comments
 (0)