From 891c98ebd63b5a5b079a1f5a2736a29d89afcbd2 Mon Sep 17 00:00:00 2001 From: Martin Klapetek Date: Fri, 4 Dec 2015 16:00:57 -0500 Subject: Don't treat "/etc/localtime" in TZ env var as a valid timezone id On some Debian distros, the TZ environment variable can be set to ":/etc/localtime", which libc defines as "default value". If this is set, the current QTimeZone parsing code will return "/etc/localtime" as the system timezone id, which is clearly wrong. So in that case, just unset the ianaId variable and let the other blocks look for the timezone. Change-Id: I3f5795d0a05f4974a60556387a07a1e2e1e7aa30 Reviewed-by: Thiago Macieira --- src/corelib/tools/qtimezoneprivate_tz.cpp | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'src/corelib/tools/qtimezoneprivate_tz.cpp') diff --git a/src/corelib/tools/qtimezoneprivate_tz.cpp b/src/corelib/tools/qtimezoneprivate_tz.cpp index 90ce8e3b68..85ed345869 100644 --- a/src/corelib/tools/qtimezoneprivate_tz.cpp +++ b/src/corelib/tools/qtimezoneprivate_tz.cpp @@ -918,6 +918,13 @@ QByteArray QTzTimeZonePrivate::systemTimeZoneId() const if (!ianaId.isEmpty() && ianaId.at(0) == ':') ianaId = ianaId.mid(1); + // The TZ value can be ":/etc/localtime" which libc considers + // to be a "default timezone", in which case it will be read + // by one of the blocks below, so unset it here so it is not + // considered as a valid/found ianaId + if (ianaId == "/etc/localtime") + ianaId.clear(); + // On Debian Etch and later /etc/localtime is real file with name held in /etc/timezone if (ianaId.isEmpty()) { QFile tzif(QStringLiteral("/etc/timezone")); -- cgit v1.2.3