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 <thiago.macieira@intel.com>
bb10
Martin Klapetek 2015-12-04 16:00:57 -05:00
parent 9dde61f4b3
commit 891c98ebd6
1 changed files with 7 additions and 0 deletions

View File

@ -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"));