php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #67563 mysqli compiled with mysqlnd does not take ipv6 adress as parameter
Submitted: 2014-07-04 00:17 UTC Modified: 2016-04-15 00:03 UTC
Votes:17
Avg. Score:3.9 ± 1.3
Reproduced:12 of 13 (92.3%)
Same Version:5 (41.7%)
Same OS:3 (25.0%)
From: bugs-php dot a2 at x25 dot pl Assigned:
Status: Open Package: MySQLi related
PHP Version: 7.0.5 OS:
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: bugs-php dot a2 at x25 dot pl
New email:
PHP Version: OS:

 

 [2014-07-04 00:17 UTC] bugs-php dot a2 at x25 dot pl
Description:
------------
mysqli compiled with mysqlnd does not take ipv6 adress as parameter

<?
mysqli_connect("2a01:43f8:4441:12e7::c8");
?>

# php-compiled-with-mysqlnd a.php
<b>Warning</b>:  mysqli_connect(): php_network_getaddresses: getaddrinfo failed: Name or service not known in <b>/root/a.php</b> on line <b>10</b><br />

# php-compiled-with-libmysql a.php
connects fine


cat /etc/hosts
2a01:43f8:4441:12e7::c8 abc

<?
mysqli_connect("abc");
?>

php-compiled-with-mysqlnd a.php
connects fine



Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2015-04-18 13:48 UTC] bobe at webnaute dot net
There is a real problem here because mysqlnd wants the IPv6 address to be enclosed in brackets (illogical since mysqli_connect() or PDO wants a host, not a url).

But when using libmysqlclient, these extensions wants the IPv6 address NOT to be enclosed in brackets.
 [2015-04-18 14:30 UTC] bobe at webnaute dot net
Here is some tests:

PDO mysql + mysqlnd:
[::1] => ok
::1 => getaddrinfo failed
mysqli_connect() + mysqlnd:
[::1] => ok
::1 => getaddrinfo failed
mysql_connect() + mysqlnd:
[::1] => Failed to parse IPv6 address "[:3306"
::1 => No such file or directory

PDO mysql + libmysqlclient:
[::1] => SQLSTATE[HY000] [2005] Unknown MySQL server host '[::1]'
::1 => ok
mysqli_connect() + libmysqlclient:
[::1] => (HY000/2005): Unknown MySQL server host '[::1]'
::1 => ok
mysql_connect() + libmysqlclient:
[::1] => Unknown MySQL server host '[' (2)
::1 => Can't connect to local MySQL server through socket '1'
 [2016-04-15 00:01 UTC] bugs-php dot a2 at x25 dot pl
-: naox at o2 dot pl +: bugs-php dot a2 at x25 dot pl -Package: MySQLi related +Package: MySQL related -PHP Version: 5.5.14 +PHP Version: 7.0.5
 [2016-04-15 00:01 UTC] bugs-php dot a2 at x25 dot pl
How many more years is needed for simple patch for mysqlnd (or mysqli) to unify how ipv6 mysql adress should be passed regardless of underlying lib? (it should be without brackets so hostnames would work)
 [2016-04-15 00:03 UTC] bugs-php dot a2 at x25 dot pl
-Package: MySQL related +Package: MySQLi related
 [2016-04-15 00:03 UTC] bugs-php dot a2 at x25 dot pl
--
 [2017-08-05 11:29 UTC] seb35 at seb35 dot fr
I don’t know well the PHP codebase, so I studied the code, searching occurences of "php_network_getaddresses" and found that this function is used in 3 other functions (all in main/network.c). One step further, it seems two functions are in charge of the parsing of IP addresses:
* php_network_parse_network_address_with_port in main/network.c
* parse_ip_address_ex in main/streams/xp_socket.c (used for mysqli_connect)

Both expect IPv6 to be enclosed in brackets, with port after the closing bracket (e.g. "[2001:db8::]:80"). The algorithm of these both functions is as follows:
1. if the first character is '[', it is considered an IPv6 address with port;
2. else it is considered an IPv4 address with port or an hostname with port.

One or two of the following proposed changes could be implemented to solve this bug.

A) A first proposed change could be the following algorithm:
1. if the first character is '[', it is considered an IPv6 address with port;
2. else, if the string contains two colons, it is considered an IPv6 with port (*);
3. else it is considered an IPv4 address with port or an hostname with port.

Such a change would have a more general scope in PHP codebase, it will solve the issue for this bug, but possibly for other similar bugs related to IPv6 parsing.

(*) an IPv6 with port contains at least two colons, at least one ':' in IPv6 and one ':' for port (e.g. "2001:db8:::80"). Given the port must be provided to these both functions, there is no ambiguity, and the last colon is the delimiter for the port.

B) A second proposed change would be to add brackets around IPv6 addresses without port when needed.

Such a change should be done in each occurence of IPv6 parsing in the whole PHP codebase.

--

For reference, the parsing of host in URI is described in RFC 3986, section 3.2.2.
 [2017-08-05 12:06 UTC] seb35 at seb35 dot fr
Well, the codebase where I conducted my search appeared to be a bit old (24 March 2017), and there were changes since this date on parse_ip_address_ex in main/streams/xp_socket.c due to #74216. I guess there will be soon other changes related to parsing of "double ports" (e.g. "127.0.0.1:53:80") and it could affect this bug, possibly solving it.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Oct 13 23:01:26 2024 UTC