Skip to content

Fix implicit/explicit port in mysqlnd #10922

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

kamil-tekiela
Copy link
Member

This fixes #8978

@cmb69 What do you think about this fix?

@kamil-tekiela kamil-tekiela requested a review from nielsdos August 10, 2023 14:44
@@ -543,7 +543,11 @@ 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);
if (strchr(hostname.s, ':') == NULL) {
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 believe this works for ipv6 addresses, because they already contain :.
e.g.: mysqli_connect("[::1]"," root", "", port: 123); this will not use port 123, it results in transport.s being tcp://[::1]. Prior to this PR it did use port 123.
But the general idea of the PR is good, it just needs fixing for ipv6 I think.

Copy link
Member

Choose a reason for hiding this comment

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

Now that I think again about this, I notice that there's also another existing issue with ipv6 here.
Omitting the square brackets, i.e. ::1 for example should also work as a hostname. But if you specify a port, then transport.s becomes ::1:portnr. This is an invalid ipv6 address.

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 wonder if it works with IPv6 at all. I found this bug https://bugs.php.net/bug.php?id=67563

Copy link
Member

Choose a reason for hiding this comment

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

Looking at the 2nd comment, they seem to suggest it works with brackets.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants