Skip to content
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions ext/mysqli/tests/bug67563.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
--TEST--
Fix bug #67563 (mysqli compiled with mysqlnd does not take ipv6 adress as parameter)
--EXTENSIONS--
mysqli
--SKIPIF--
<?php
require_once 'connect.inc';

if ($host !== '127.0.0.1') die('skip local test');

if (!$link = @my_mysqli_connect($host, $user, $passwd, $db, $port, $socket)) {
die(sprintf("SKIP Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n",
$host, $user, $db, $port, $socket));
}
?>
--INI--
max_execution_time=240
--FILE--
<?php
require_once 'connect.inc';

$host = '::1';

if (!$link = my_mysqli_connect($host, 'pamtest', 'pamtest', $db, $port, $socket)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (!$link = my_mysqli_connect($host, 'pamtest', 'pamtest', $db, $port, $socket)) {
if (!$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket)) {

Should it not be like this?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I copied this from somewhere, still have to make it work

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know why but I am getting a memory leak when running this patch:

004+ [001] Cannot connect to the server using host=::1, user=pamtest, passwd=pamtest dbname=test, port=3306, socket=
005+ done![Tue Sep 30 12:06:46 2025]  Script:  '/mnt/f/projects/php-src/ext/mysqli/tests/bug67563.php'
006+ /mnt/f/projects/php-src/Zend/zend_smart_str.c(172) :  Freeing 0x00007f2516494300 (224 bytes), script=/mnt/f/projects/php-src/ext/mysqli/tests/bug67563.php
007+ === Total 1 memory leaks detected ===

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't be introduced by this patch. I suppose it's a pre-existing bug where on failure something isn't freed. I can take a look after a while. I'll let CI run first.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't trigger that leak on my system

printf("[001] Cannot connect to the server using host=%s, user=pamtest, passwd=pamtest dbname=%s, port=%s, socket=%s\n",
$host, $db, $port, $socket);
} else {
$link->close();
}

print "done!";
?>
--EXPECT--
done!
18 changes: 17 additions & 1 deletion ext/mysqlnd/mysqlnd_connection.c
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,16 @@ MYSQLND_METHOD(mysqlnd_conn_data, connect_handshake)(MYSQLND_CONN_DATA * conn,
}
/* }}} */

/* ipv6 addresses have at least two colons, which is how we can differentiate between domain names and addresses */
static bool mysqlnd_fast_is_ipv6_address(const char *s)
{
const char *first_colon = strchr(s, ':');
if (!first_colon) {
return false;
}
return strchr(first_colon + 1, ':') != NULL;
}

/* {{{ mysqlnd_conn_data::get_scheme */
static MYSQLND_STRING
MYSQLND_METHOD(mysqlnd_conn_data, get_scheme)(MYSQLND_CONN_DATA * conn, MYSQLND_CSTRING hostname, MYSQLND_CSTRING *socket_or_pipe, unsigned int port, bool * unix_socket, bool * named_pipe)
Expand Down Expand Up @@ -542,7 +552,13 @@ MYSQLND_METHOD(mysqlnd_conn_data, get_scheme)(MYSQLND_CONN_DATA * conn, MYSQLND_
if (!port) {
port = 3306;
}
transport.l = mnd_sprintf(&transport.s, 0, "tcp://%s:%u", hostname.s, port);

/* ipv6 addresses are in the format [address]:port */
if (hostname.s[0] != '[' && mysqlnd_fast_is_ipv6_address(hostname.s)) {
transport.l = mnd_sprintf(&transport.s, 0, "tcp://[%s]:%u", hostname.s, port);
} else {
transport.l = mnd_sprintf(&transport.s, 0, "tcp://%s:%u", hostname.s, port);
}
}
DBG_INF_FMT("transport=%s", transport.s? transport.s:"OOM");
DBG_RETURN(transport);
Expand Down
Loading