diff options
author | Edward Welbourne <edward.welbourne@qt.io> | 2020-08-13 10:40:11 +0200 |
---|---|---|
committer | Edward Welbourne <edward.welbourne@qt.io> | 2020-08-23 09:55:29 +0200 |
commit | 14f3f419b0864944d75283a850dc0ce141feaf0e (patch) | |
tree | 6a42b84eb98778e85ab982884b2e9bd616eff528 /src/corelib/time | |
parent | 33031020e1bd35b52b91aea0b899756c59bf62e6 (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
Pick-to: 5.15
Pick-to: 5.12
Change-Id: I6882026403d00f8b254aab34c645f1cf8f9fcc2d
Reviewed-by: Taylor Braun-Jones <taylor@braun-jones.org>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/time')
-rw-r--r-- | src/corelib/time/qtimezone.cpp | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/src/corelib/time/qtimezone.cpp b/src/corelib/time/qtimezone.cpp index 24834d1284..684639b68e 100644 --- a/src/corelib/time/qtimezone.cpp +++ b/src/corelib/time/qtimezone.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2013 John Layt <jlayt@kde.org> +** Copyright (C) 2020 John Layt <jlayt@kde.org> ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the QtCore module of the Qt Toolkit. @@ -966,9 +966,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; } @@ -976,7 +982,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; |