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 <alexis.menard@openbossa.org>
Reviewed-by: Lars Knoll <lars.knoll@nokia.com>
This commit is contained in:
Thiago Macieira 2012-05-08 13:31:12 -07:00 committed by Qt by Nokia
parent ff3a2ab242
commit 75552c8f62
2 changed files with 11 additions and 1 deletions

View File

@ -777,7 +777,7 @@ void QUrlPrivate::setUserInfo(const QString &userInfo, int from, int end)
int delimIndex = userInfo.indexOf(QLatin1Char(':'), from);
setUserName(userInfo, from, qMin<uint>(delimIndex, end));
if (delimIndex == -1) {
if (uint(delimIndex) >= uint(end)) {
password.clear();
sectionIsPresent &= ~Password;
sectionHasError &= ~Password;

View File

@ -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());