QIpAddress: reject IPv6 addresses with more than 4 hex digits
Matches glibc commit 9a0cc8c1bd7645bf3c988890ffb59639c07a5812. [ChangeLog][QtCore][QUrl] Fixed a bug in parsing IPv6 addresses with more than 4 hex digits in a component. [ChangeLog][QtNetwork][QHostAddress] Fixed a bug in parsing IPv6 addresses with more than 4 hex digits in a component. [1] https://sourceware.org/git/?p=glibc.git;a=commit;h=9a0cc8c1bd7645bf3c988890ffb59639c07a5812 Change-Id: I2701038131d91eb108aebb3bec16278e4efe3de2 Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
This commit is contained in:
parent
53f82185e9
commit
2fb706f9a8
@ -216,7 +216,10 @@ const QChar *parseIp6(IPv6Address &address, const QChar *begin, const QChar *end
|
|||||||
quint64 ll = qstrtoull(ptr, &endptr, 16, &ok);
|
quint64 ll = qstrtoull(ptr, &endptr, 16, &ok);
|
||||||
quint16 x = ll;
|
quint16 x = ll;
|
||||||
|
|
||||||
if (!ok || ll != x)
|
// Reject malformed fields:
|
||||||
|
// - failed to parse
|
||||||
|
// - too many hex digits
|
||||||
|
if (!ok || endptr > ptr + 4)
|
||||||
return begin + (ptr - buffer.data());
|
return begin + (ptr - buffer.data());
|
||||||
|
|
||||||
if (*endptr == '.') {
|
if (*endptr == '.') {
|
||||||
|
@ -288,9 +288,6 @@ void tst_QIpAddress::parseIp6_data()
|
|||||||
<< "ffee:ddcc:bbaa:9988:7766:5544:3322:1100"
|
<< "ffee:ddcc:bbaa:9988:7766:5544:3322:1100"
|
||||||
<< Ip6(0xffee, 0xddcc, 0xbbaa, 0x9988, 0x7766, 0x5544, 0x3322, 0x1100);
|
<< Ip6(0xffee, 0xddcc, 0xbbaa, 0x9988, 0x7766, 0x5544, 0x3322, 0x1100);
|
||||||
|
|
||||||
// too many zeroes
|
|
||||||
QTest::newRow("0:0:0:0:0:0:0:00103") << "0:0:0:0:0:0:0:00103" << Ip6(0,0,0,0,0,0,0,0x103);
|
|
||||||
|
|
||||||
// double-colon
|
// double-colon
|
||||||
QTest::newRow("::1:2:3:4:5:6:7") << "::1:2:3:4:5:6:7" << Ip6(0,1,2,3,4,5,6,7);
|
QTest::newRow("::1:2:3:4:5:6:7") << "::1:2:3:4:5:6:7" << Ip6(0,1,2,3,4,5,6,7);
|
||||||
QTest::newRow("1:2:3:4:5:6:7::") << "1:2:3:4:5:6:7::" << Ip6(1,2,3,4,5,6,7,0);
|
QTest::newRow("1:2:3:4:5:6:7::") << "1:2:3:4:5:6:7::" << Ip6(1,2,3,4,5,6,7,0);
|
||||||
@ -382,6 +379,9 @@ void tst_QIpAddress::invalidParseIp6_data()
|
|||||||
// too big number
|
// too big number
|
||||||
QTest::newRow("0:0:0:0:0:0:0:10103") << "0:0:0:0:0:0:0:10103";
|
QTest::newRow("0:0:0:0:0:0:0:10103") << "0:0:0:0:0:0:0:10103";
|
||||||
|
|
||||||
|
// too many zeroes
|
||||||
|
QTest::newRow("0:0:0:0:0:0:0:00103") << "0:0:0:0:0:0:0:00103";
|
||||||
|
|
||||||
// too short
|
// too short
|
||||||
QTest::newRow("0:0:0:0:0:0:0:") << "0:0:0:0:0:0:0:";
|
QTest::newRow("0:0:0:0:0:0:0:") << "0:0:0:0:0:0:0:";
|
||||||
QTest::newRow("0:0:0:0:0:0:0") << "0:0:0:0:0:0:0";
|
QTest::newRow("0:0:0:0:0:0:0") << "0:0:0:0:0:0:0";
|
||||||
@ -438,6 +438,8 @@ void tst_QIpAddress::invalidParseIp6()
|
|||||||
#if defined(__GLIBC__) && defined(AF_INET6)
|
#if defined(__GLIBC__) && defined(AF_INET6)
|
||||||
Ip6 inet_result;
|
Ip6 inet_result;
|
||||||
bool inet_ok = inet_pton(AF_INET6, address.toLatin1(), &inet_result.u8);
|
bool inet_ok = inet_pton(AF_INET6, address.toLatin1(), &inet_result.u8);
|
||||||
|
if (__GLIBC_MINOR__ < 26)
|
||||||
|
QEXPECT_FAIL("0:0:0:0:0:0:0:00103", "Bug fixed in glibc 2.26", Continue);
|
||||||
QVERIFY(!inet_ok);
|
QVERIFY(!inet_ok);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user