Return early from QTimeZone constructor if alleged IANA ID is invalid

If the ID isn't even valid, don't waste cycles trying to make sense of
it as identifying a time-zone.

Add test of an invalid ID that provoked an integer overflow on trying
to parse it as a POSIX zone specification.

Fixes: QTBUG-92842
Change-Id: Ib80bbb88c11c0484ce0358acabbdc25c5bd8e0b3
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
Edward Welbourne 2021-04-19 13:30:19 +02:00
parent e41dbfd3a4
commit ec8808c302
2 changed files with 6 additions and 0 deletions

View File

@ -334,6 +334,9 @@ QTimeZone::QTimeZone() noexcept
QTimeZone::QTimeZone(const QByteArray &ianaId)
{
// If invalid (other than empty), reject immediately:
if (!ianaId.isEmpty() && !QTimeZonePrivate::isValidId(ianaId))
return;
// Try and see if it's a CLDR UTC offset ID - just as quick by creating as
// by looking up.
d = new QUtcTimeZonePrivate(ianaId);

View File

@ -1000,6 +1000,9 @@ void tst_QTimeZone::malformed()
barf = QTimeZone("QtC+09,,MA");
if (barf.isValid())
QCOMPARE(barf.offsetFromUtc(now), 0);
barf = QTimeZone("UTCC+14:00,-,");
if (barf.isValid())
QCOMPARE(barf.daylightTimeOffset(now), -14 * 3600);
}
void tst_QTimeZone::utcTest()