diff options
author | Edward Welbourne <edward.welbourne@qt.io> | 2020-08-13 10:40:11 +0200 |
---|---|---|
committer | Edward Welbourne <edward.welbourne@qt.io> | 2020-09-03 10:14:23 +0200 |
commit | f919d9a2dad9412c64e74b19eee2b8429da2d3bb (patch) | |
tree | cc6d8be9129c660547c20aeb714114196553f7d8 /src/corelib | |
parent | 5cbebeda54c81a182b8581a2d0a7f4b6b00e45f8 (diff) |
Fix crash on serializing default-constructed QTimeZone
The serialization code neglected to check against null. Sinze zones
are saved either by IANA ID or in our special OffsetFromUtc format,
representing an invalid zone by a string that cannot possibly be a
valid IANA ID will do.
Fixes: QTBUG-86019
Change-Id: I6882026403d00f8b254aab34c645f1cf8f9fcc2d
Reviewed-by: Taylor Braun-Jones <taylor@braun-jones.org>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
(cherry picked from commit 14f3f419b0864944d75283a850dc0ce141feaf0e)
Diffstat (limited to 'src/corelib')
-rw-r--r-- | src/corelib/tools/qtimezone.cpp | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/src/corelib/tools/qtimezone.cpp b/src/corelib/tools/qtimezone.cpp index cbc6b50c98..e0ce5dcd0d 100644 --- a/src/corelib/tools/qtimezone.cpp +++ b/src/corelib/tools/qtimezone.cpp @@ -1,5 +1,6 @@ /**************************************************************************** ** +** Copyright (C) 2020 The Qt Company Ltd. ** Copyright (C) 2013 John Layt <jlayt@kde.org> ** Contact: https://www.qt.io/licensing/ ** @@ -953,9 +954,15 @@ QList<QByteArray> QTimeZone::windowsIdToIanaIds(const QByteArray &windowsId, } #ifndef QT_NO_DATASTREAM +// Invalid, as an IANA ID: too long, starts with - and has other invalid characters in it +static inline QString invalidId() { return QStringLiteral("-No Time Zone Specified!"); } + QDataStream &operator<<(QDataStream &ds, const QTimeZone &tz) { - tz.d->serialize(ds); + if (tz.isValid()) + tz.d->serialize(ds); + else + ds << invalidId(); return ds; } @@ -963,7 +970,9 @@ QDataStream &operator>>(QDataStream &ds, QTimeZone &tz) { QString ianaId; ds >> ianaId; - if (ianaId == QLatin1String("OffsetFromUtc")) { + if (ianaId == invalidId()) { + tz = QTimeZone(); + } else if (ianaId == QLatin1String("OffsetFromUtc")) { int utcOffset; QString name; QString abbreviation; |