Skip to content

Commit 448ef30

Browse files
committed
Handle NULL strings in sapi_cli_server_register_variable().
Fixes bug #68745 (Invalid HTTP requests make web server segfault).
1 parent 0cc2810 commit 448ef30

File tree

3 files changed

+42
-0
lines changed

3 files changed

+42
-0
lines changed

NEWS

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

26+
- CLI server:
27+
. Fix bug #68745 (Invalid HTTP requests make web server segfault). (Adam)
28+
2629
- cURL:
2730
. Fixed bug #67643 (curl_multi_getcontent returns '' when
2831
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/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
33+
34+
int(%d)

0 commit comments

Comments
 (0)