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

Merge branch 'PHP-8.4' into PHP-8.5

* PHP-8.4:
  NEWS
  NEWS
  Fix GH-20528: Regression breaks mysql connexion using an IPv6 address enclosed in square brackets
This commit is contained in:
Remi Collet
2025-11-21 09:20:41 +01:00
2 changed files with 45 additions and 3 deletions

View File

@@ -0,0 +1,31 @@
--TEST--
mysqli_connect() with port in host
--EXTENSIONS--
mysqli
--SKIPIF--
<?php
require_once 'skipifconnectfailure.inc';
?>
--FILE--
<?php
require_once 'connect.inc';
// using port / host arguments
if (!$link = mysqli_connect($host, $user, $passwd, $db, $port, $socket)) {
printf("Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n",
$host, $user, $db, $port, $socket);
}
mysqli_close($link);
// using port in host
if (!$link = mysqli_connect("$host:$port", $user, $passwd, $db, "1$port", $socket)) {
printf("Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n",
"$host:$port", $user, $db, "1$port", $socket);
}
mysqli_close($link);
?>
Done
--EXPECTF--
Done

View File

@@ -548,13 +548,24 @@ MYSQLND_METHOD(mysqlnd_conn_data, get_scheme)(MYSQLND_CONN_DATA * conn, MYSQLND_
port = 3306;
}
/* ipv6 addresses are in the format [address]:port */
if (hostname.s[0] != '[' && mysqlnd_fast_is_ipv6_address(hostname.s)) {
/* IPv6 without square brackets so without port */
transport.l = mnd_sprintf(&transport.s, 0, "tcp://[%s]:%u", hostname.s, port);
} else {
/* Not ipv6, but could already contain a port number, in which case we should not add an extra port.
char *p;
/* IPv6 addresses are in the format [address]:port */
if (hostname.s[0] == '[') { /* IPv6 */
p = strchr(hostname.s, ']');
if (p && p[1] != ':') {
p = NULL;
}
} else { /* IPv4 or name */
p = strchr(hostname.s, ':');
}
/* Could already contain a port number, in which case we should not add an extra port.
* See GH-8978. In a port doubling scenario, the first port would be used so we do the same to keep BC. */
if (strchr(hostname.s, ':')) {
if (p) {
/* TODO: Ideally we should be able to get rid of this workaround in the future. */
transport.l = mnd_sprintf(&transport.s, 0, "tcp://%s", hostname.s);
} else {