diff --git a/NEWS b/NEWS index 795da1d8b5b..6472816e407 100644 --- a/NEWS +++ b/NEWS @@ -13,6 +13,10 @@ PHP NEWS deprecated. (alexandre-daubois) . Fixed bug GH-19681 (PHP_EXPAND_PATH broken with bash 5.3.0). (Remi) +- CLI: + . Fixed bug GH-19461 (Improve error message on listening error with IPv6 + address). (alexandre-daubois) + - Date: . Fixed date_sunrise() and date_sunset() with partial-hour UTC offset. (ilutov) diff --git a/sapi/cli/php_cli_server.c b/sapi/cli/php_cli_server.c index 92c6ecbdfb5..911cfd2bb59 100644 --- a/sapi/cli/php_cli_server.c +++ b/sapi/cli/php_cli_server.c @@ -2563,7 +2563,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); } diff --git a/sapi/cli/tests/php_cli_server_ipv4_error_message.phpt b/sapi/cli/tests/php_cli_server_ipv4_error_message.phpt new file mode 100644 index 00000000000..71280179ccc --- /dev/null +++ b/sapi/cli/tests/php_cli_server_ipv4_error_message.phpt @@ -0,0 +1,41 @@ +--TEST-- +IPv4 address error message formatting +--SKIPIF-- + +--FILE-- + 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 +" diff --git a/sapi/cli/tests/php_cli_server_ipv6_error_message.phpt b/sapi/cli/tests/php_cli_server_ipv6_error_message.phpt new file mode 100644 index 00000000000..55432eeec15 --- /dev/null +++ b/sapi/cli/tests/php_cli_server_ipv6_error_message.phpt @@ -0,0 +1,40 @@ +--TEST-- +IPv6 address error message formatting +--SKIPIF-- + +--FILE-- + 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 +"