Bug #74557 [NEW]: mysqlnd doesn't support IPv6 literal hostnames
From: paul at packetship dot com
Operating system: Linux
PHP version: master-Git-2017-05-08 (Git)
Package: MySQL related
Bug Type: Bug
Bug description:mysqlnd doesn't support IPv6 literal hostnames
Description:
------------
(tested on PHP 7.0.15-0ubuntu0.16.04.4 but verified from git master
source)
Attempting to connect to an IPv6 MySQL server using its literal IPv6
address fails unless you put square brackets [ ] around the address in
the hostname.
Square brackets are required in the URL form if there is a port - e.g.
http://[1234:5678::42]:8080/
but are not normally used for hostnames by themselves.
Although putting [ ] around the hostname makes it work - e.g.
$pdo = new PDO("mysql:host=[1234:5678::42];port=3306;dbname=foo",
...);
this is not expected, or documented.
The problem arises because the mysqlnd driver reconstructs a stream URL
with the hostname and port:
transport.l = mnd_sprintf(&transport.s, 0, "tcp://%s:%u", hostname.s,
port);
(
https://github.com/php/php-src/blob/master/ext/mysqlnd/mysqlnd_connection.c#L581
)
This does not take into account that the hostname could already contain
colons in an IPv6 address. The IP address parser (
https://github.com/php/php-src/blob/master/main/streams/xp_socket.c#L573
) has code to work this out if there are square brackets around the IPv6
address, but fails otherwise. This is why putting square brackets
around the hostname in the PDO string works.
The fix would be to check for ':' in the hostname and surround it with [
] if present - e.g.
around mysqlnd_connection.c:L581
if (strchr(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);
(or something like that, PHP-style C is not my language, I'm afraid!)
--
Edit bug report at https://bugs.php.net/bug.php?id=74557&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=74557&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=74557&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=74557&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=74557&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=74557&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=74557&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=74557&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=74557&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=74557&r=support
Expected behavior: https://bugs.php.net/fix.php?id=74557&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=74557&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=74557&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=74557&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=74557&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=74557&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=74557&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=74557&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=74557&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=74557&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=74557&r=mysqlcfg
Thread (1 message)
- paul at packetship dot com