Skip to content

Commit 1d7573b

Browse files
Fix GH-19461: Improve error message on listening error with IPv6
1 parent 9b86533 commit 1d7573b

File tree

4 files changed

+90
-1
lines changed

4 files changed

+90
-1
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ PHP NEWS
22
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
33
?? ??? ????, PHP 8.3.25
44

5+
- CLI:
6+
. Fixed bug GH-19461 (Improve error message on listening error with IPv6
7+
address). (alexandre-daubois)
8+
59
- Core:
610
. Fixed GH-19169 build issue with C++17 and ZEND_STATIC_ASSERT macro.
711
(psumbera)

sapi/cli/php_cli_server.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2572,7 +2572,11 @@ static zend_result php_cli_server_ctor(php_cli_server *server, const char *addr,
25722572

25732573
server_sock = php_network_listen_socket(host, &port, SOCK_STREAM, &server->address_family, &server->socklen, &errstr);
25742574
if (server_sock == SOCK_ERR) {
2575-
php_cli_server_logf(PHP_CLI_SERVER_LOG_ERROR, "Failed to listen on %s:%d (reason: %s)", host, port, errstr ? ZSTR_VAL(errstr) : "?");
2575+
if (strchr(host, ':')) {
2576+
php_cli_server_logf(PHP_CLI_SERVER_LOG_ERROR, "Failed to listen on [%s]:%d (reason: %s)", host, port, errstr ? ZSTR_VAL(errstr) : "?");
2577+
} else {
2578+
php_cli_server_logf(PHP_CLI_SERVER_LOG_ERROR, "Failed to listen on %s:%d (reason: %s)", host, port, errstr ? ZSTR_VAL(errstr) : "?");
2579+
}
25762580
if (errstr) {
25772581
zend_string_release_ex(errstr, 0);
25782582
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
--TEST--
2+
IPv4 address error message formatting
3+
--SKIPIF--
4+
<?php
5+
if (substr(PHP_OS, 0, 3) == 'WIN') {
6+
die("skip not for Windows");
7+
}
8+
?>
9+
--FILE--
10+
<?php
11+
12+
$descriptorspec = array(
13+
0 => array("pipe", "r"),
14+
1 => array("pipe", "w"),
15+
2 => array("pipe", "w")
16+
);
17+
18+
$process = proc_open(
19+
PHP_BINARY . ' -S "192.168.1.999:8080"',
20+
$descriptorspec,
21+
$pipes
22+
);
23+
24+
if (is_resource($process)) {
25+
usleep(100000);
26+
27+
$stderr = stream_get_contents($pipes[2]);
28+
29+
fclose($pipes[0]);
30+
fclose($pipes[1]);
31+
fclose($pipes[2]);
32+
33+
proc_terminate($process);
34+
proc_close($process);
35+
36+
var_dump($stderr);
37+
}
38+
?>
39+
--EXPECTF--
40+
string(%d) "[%s] Failed to listen on 192.168.1.999:8080 %s
41+
"
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
--TEST--
2+
IPv6 address error message formatting
3+
--SKIPIF--
4+
<?php
5+
if (substr(PHP_OS, 0, 3) == 'WIN') {
6+
die("skip not for Windows");
7+
}
8+
?>
9+
--FILE--
10+
<?php
11+
$descriptorspec = array(
12+
0 => array("pipe", "r"),
13+
1 => array("pipe", "w"),
14+
2 => array("pipe", "w")
15+
);
16+
17+
$process = proc_open(
18+
PHP_BINARY . ' -S "[1234:1234:1234:1234::4321]:8080"',
19+
$descriptorspec,
20+
$pipes
21+
);
22+
23+
if (is_resource($process)) {
24+
usleep(100000);
25+
26+
$stderr = stream_get_contents($pipes[2]);
27+
28+
fclose($pipes[0]);
29+
fclose($pipes[1]);
30+
fclose($pipes[2]);
31+
32+
proc_terminate($process);
33+
proc_close($process);
34+
35+
var_dump($stderr);
36+
}
37+
?>
38+
--EXPECTF--
39+
string(%d) "[%s] Failed to listen on [1234:1234:1234:1234::4321]:8080 %s
40+
"

0 commit comments

Comments
 (0)