Check time-text is long enough while checking for its colons

Added some tests that trigger an assert without this check.
(Drive-by: renamed one QTime test to match its QDate(Time)? counterparts.)

Change-Id: I3d6767605fdcca13a9b4d43a32904f584eb57cf9
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Reviewed-by: Andrei Golubev <andrei.golubev@qt.io>
Reviewed-by: Andreas Buhr <andreas.buhr@qt.io>
bb10
Edward Welbourne 2020-09-18 16:31:13 +02:00
parent 9d2a107da2
commit 229c9736bb
4 changed files with 10 additions and 2 deletions

View File

@ -229,8 +229,10 @@ static ParsedRfcDateTime rfcDateImpl(QStringView s)
QTime time;
if (words.size() && words.at(0).contains(colon)) {
const QStringView when = words.takeFirst();
if (when[2] != colon || (when.size() == 8 ? when[5] != colon : when.size() > 5))
if (when.size() < 5 || when[2] != colon
|| (when.size() == 8 ? when[5] != colon : when.size() > 5)) {
return result;
}
const int hour = when.left(2).toInt(&ok);
if (!ok)
return result;

View File

@ -1149,6 +1149,8 @@ void tst_QDate::fromStringDateFormat_data()
<< Qt::RFC2822Date << QDate(2002, 11, 1);
QTest::newRow("RFC 2822 with day date only") << QString::fromLatin1("Fri, 01 Nov 2002")
<< Qt::RFC2822Date << QDate(2002, 11, 1);
QTest::newRow("RFC 2822 malformed time")
<< QString::fromLatin1("01 Nov 2002 0:") << Qt::RFC2822Date << QDate();
// Test invalid month, day, year
QTest::newRow("RFC 2822 invalid month name") << QString::fromLatin1("13 Fev 1987 13:24:51 +0100")
<< Qt::RFC2822Date << QDate();

View File

@ -2508,6 +2508,8 @@ void tst_QDateTime::fromStringDateFormat_data()
<< Qt::RFC2822Date << QDateTime();
QTest::newRow("RFC 2822 with day date only") << QString::fromLatin1("Fri, 01 Nov 2002")
<< Qt::RFC2822Date << QDateTime();
QTest::newRow("RFC 2822 malformed time")
<< QString::fromLatin1("01 Nov 2002 0:") << Qt::RFC2822Date << QDateTime();
// Test invalid month, day, year
QTest::newRow("RFC 2822 invalid month name") << QString::fromLatin1("13 Fev 1987 13:24:51 +0100")
<< Qt::RFC2822Date << QDateTime();

View File

@ -651,6 +651,8 @@ void tst_QTime::fromStringDateFormat_data()
<< Qt::RFC2822Date << invalidTime();
QTest::newRow("RFC 2822 with day date only") << QString::fromLatin1("Fri, 01 Nov 2002")
<< Qt::RFC2822Date << invalidTime();
QTest::newRow("RFC 2822 malformed time")
<< QString::fromLatin1("01 Nov 2002 0:") << Qt::RFC2822Date << QTime();
// Test invalid month, day, year are ignored:
QTest::newRow("RFC 2822 invalid month name") << QString::fromLatin1("13 Fev 1987 13:24:51 +0100")
<< Qt::RFC2822Date << QTime(13, 24, 51);
@ -678,7 +680,7 @@ void tst_QTime::fromStringDateFormat_data()
<< Qt::RFC2822Date << invalidTime();
// The common date text used by the "invalid character" tests, just to be
// sure *it's* not what's invalid:
QTest::newRow("RFC 2822 invalid character at end")
QTest::newRow("RFC 2822 (not invalid)")
<< QString::fromLatin1("01 Jan 2012 08:00:00 +0100")
<< Qt::RFC2822Date << QTime(8, 0, 0);