Skip to content

Conversation

nielsdos
Copy link
Member

@nielsdos nielsdos commented Sep 7, 2025

In the past, when libmysqlclient could be used, it accepted ipv6 addresses as hostname without enclosing it first in brackets. However, in mysqlnd this never worked. In the past this caused a discrepancy between the two implementations.
Nowadays, mysqli only works with mysqlnd so we don't even have to cater to libmysqlclient. However, a plain ipv6 address should still work as a hostname. Also for people migrating to newer PHP versions it's nice if this keeps working.

The solution is to check if we're dealing with an ipv6 address not yet enclosed in brackets. In that case we add the brackets automatically.


Testing this automatically seems not straight-forward. The connection string is not logged. Using the fake server requires modifications to specify a host and can't be easily reused in the same phpt file. This was tested by hand.

…s as parameter

In the past, when libmysqlclient could be used, it accepted ipv6 addresses
as hostname without enclosing it first in brackets. However, in mysqlnd
this never worked. In the past this caused a discrepancy between the two
implementations.
Nowadays, mysqli only works with mysqlnd so we don't even have to cater
to libmysqlclient. However, a plain ipv6 address should still work as a
hostname. Also for people migrating to newer PHP versions it's nice if
this keeps working.

The solution is to check if we're dealing with an ipv6 address not yet
enclosed in brackets. In that case we add the brackets automatically.
@nielsdos nielsdos changed the base branch from master to PHP-8.3 September 7, 2025 19:12
Copy link
Member

@kamil-tekiela kamil-tekiela left a comment

Choose a reason for hiding this comment

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

I am not going to test it but if you have tested that it works then you can merge it. I doubt anyone is using this feature, but in the future someone might.

How does this impact PDO? Is this a new feature in PDO too?

@nielsdos
Copy link
Member Author

nielsdos commented Sep 7, 2025

How does this impact PDO? Is this a new feature in PDO too?

This should now also work properly in PDO-MYQSL, whereas previously it did not work.
I don't see it as a new feature though, the address that mysqlnd created was malformed so for me that's a bug 🙂

@bukka
Copy link
Member

bukka commented Sep 10, 2025

The change looks good - nice and simple!

About the test, CI should support ::1 and think it's even resolving localhost to ::1 so why can't you add a test connection to ::1 (with maybe some grant update if needed)?


$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

@nielsdos
Copy link
Member Author

CI finally green after fighting CI a bit

@nielsdos nielsdos closed this in 6db12e7 Sep 30, 2025
@kamil-tekiela
Copy link
Member

Is there a way to modify the test so that if the MySQL server is not configured for IPv6, it doesn't fail?

@nielsdos
Copy link
Member Author

nielsdos commented Oct 9, 2025

Is there a way to modify the test so that if the MySQL server is not configured for IPv6, it doesn't fail?

I suppose it could test [::1] as a host in the skipif

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants