From 75552c8f62dcfb8012c306b37c79ec629448d780 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Tue, 8 May 2012 13:31:12 -0700 Subject: Fix a crash when parsing a URL with username and port, but no password This was crashing because the ':' was found past the end of the username, causing the recoder to run from position 22 to 11, via the long way around the memory. Change-Id: Ic1ae596f34f7db857fb4210294974fb5a6adf691 Reviewed-by: Alexis Menard Reviewed-by: Lars Knoll --- src/corelib/io/qurl.cpp | 2 +- tests/auto/corelib/io/qurl/tst_qurl.cpp | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/corelib/io/qurl.cpp b/src/corelib/io/qurl.cpp index f975fb4e43..3e711b12ec 100644 --- a/src/corelib/io/qurl.cpp +++ b/src/corelib/io/qurl.cpp @@ -777,7 +777,7 @@ void QUrlPrivate::setUserInfo(const QString &userInfo, int from, int end) int delimIndex = userInfo.indexOf(QLatin1Char(':'), from); setUserName(userInfo, from, qMin(delimIndex, end)); - if (delimIndex == -1) { + if (uint(delimIndex) >= uint(end)) { password.clear(); sectionIsPresent &= ~Password; sectionHasError &= ~Password; diff --git a/tests/auto/corelib/io/qurl/tst_qurl.cpp b/tests/auto/corelib/io/qurl/tst_qurl.cpp index 46d491ba79..63f9cd06dc 100644 --- a/tests/auto/corelib/io/qurl/tst_qurl.cpp +++ b/tests/auto/corelib/io/qurl/tst_qurl.cpp @@ -410,6 +410,16 @@ void tst_QUrl::setUrl() QCOMPARE(url.toDisplayString(), QString::fromLatin1("http://user@[56::56:56:56:7f00:1]:99")); } + { + QUrl url("http://user@localhost:8000/xmlhttprequest/resources/basic-auth-nouserpass/basic-auth-nouserpass.php"); + QVERIFY(url.isValid()); + QCOMPARE(url.scheme(), QString::fromLatin1("http")); + QCOMPARE(url.userName(), QString::fromLatin1("user")); + QCOMPARE(url.password(), QString()); + QCOMPARE(url.userInfo(), QString::fromLatin1("user")); + QCOMPARE(url.port(), 8000); + } + { QUrl url("http://www.foo.bar"); QVERIFY(url.isValid()); -- cgit v1.2.3