1
0
mirror of https://github.com/php/php-src.git synced 2026-03-24 00:02:20 +01:00

Fix GH-19461: Improve error message on listening error with IPv6 (#19462)

This commit is contained in:
Alexandre Daubois
2025-09-05 10:48:33 +02:00
committed by GitHub
parent abbf84083a
commit a41cb62c4c
4 changed files with 90 additions and 1 deletions

4
NEWS
View File

@@ -23,6 +23,10 @@ PHP NEWS
- FPM:
. Fixed failed debug assertion when php_admin_value setting fails. (ilutov)
- CLI:
. Fixed bug GH-19461 (Improve error message on listening error with IPv6
address). (alexandre-daubois)
- OpenSSL:
. Fixed bug GH-19245 (Success error message on TLS stream accept failure).
(Jakub Zelenka)

View File

@@ -2572,7 +2572,11 @@ static zend_result php_cli_server_ctor(php_cli_server *server, const char *addr,
server_sock = php_network_listen_socket(host, &port, SOCK_STREAM, &server->address_family, &server->socklen, &errstr);
if (server_sock == SOCK_ERR) {
php_cli_server_logf(PHP_CLI_SERVER_LOG_ERROR, "Failed to listen on %s:%d (reason: %s)", host, port, errstr ? ZSTR_VAL(errstr) : "?");
if (strchr(host, ':')) {
php_cli_server_logf(PHP_CLI_SERVER_LOG_ERROR, "Failed to listen on [%s]:%d (reason: %s)", host, port, errstr ? ZSTR_VAL(errstr) : "?");
} else {
php_cli_server_logf(PHP_CLI_SERVER_LOG_ERROR, "Failed to listen on %s:%d (reason: %s)", host, port, errstr ? ZSTR_VAL(errstr) : "?");
}
if (errstr) {
zend_string_release_ex(errstr, 0);
}

View File

@@ -0,0 +1,41 @@
--TEST--
IPv4 address error message formatting
--SKIPIF--
<?php
if (substr(PHP_OS, 0, 3) == 'WIN') {
die("skip not for Windows");
}
?>
--FILE--
<?php
$descriptorspec = array(
0 => array("pipe", "r"),
1 => array("pipe", "w"),
2 => array("pipe", "w")
);
$process = proc_open(
PHP_BINARY . ' -S "192.168.1.999:8080"',
$descriptorspec,
$pipes
);
if (is_resource($process)) {
usleep(100000);
$stderr = stream_get_contents($pipes[2]);
fclose($pipes[0]);
fclose($pipes[1]);
fclose($pipes[2]);
proc_terminate($process);
proc_close($process);
var_dump($stderr);
}
?>
--EXPECTF--
string(%d) "[%s] Failed to listen on 192.168.1.999:8080 %s
"

View File

@@ -0,0 +1,40 @@
--TEST--
IPv6 address error message formatting
--SKIPIF--
<?php
if (substr(PHP_OS, 0, 3) == 'WIN') {
die("skip not for Windows");
}
?>
--FILE--
<?php
$descriptorspec = array(
0 => array("pipe", "r"),
1 => array("pipe", "w"),
2 => array("pipe", "w")
);
$process = proc_open(
PHP_BINARY . ' -S "[2001:db8::]:8080"',
$descriptorspec,
$pipes
);
if (is_resource($process)) {
usleep(100000);
$stderr = stream_get_contents($pipes[2]);
fclose($pipes[0]);
fclose($pipes[1]);
fclose($pipes[2]);
proc_terminate($process);
proc_close($process);
var_dump($stderr);
}
?>
--EXPECTF--
string(%d) "[%s] Failed to listen on [2001:db8::]:8080 %s
"