]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
timedatectl: assert timezone is not null in setenv() call. 993/head
authorDimitri John Ledkov <dimitri.j.ledkov@intel.com>
Wed, 19 Aug 2015 10:03:58 +0000 (10:03 +0000)
committerDimitri John Ledkov <dimitri.j.ledkov@intel.com>
Wed, 19 Aug 2015 10:04:00 +0000 (10:04 +0000)
setenv is declared as:

extern int setenv (const char *__name, const char *__value, int __replace)
     __THROW __nonnull ((2));

And i->timezone can be NULL, if for example /etc/localtime is
missing. Previously that worked, but now result in a libc dumping
core, as seen with gcc 2.22, due to:

https://sourceware.org/ml/glibc-cvs/2015-q2/msg00075.html

src/timedate/timedatectl.c

index 240578bca0fafb19ee6696b24075428594d33a27..8ec6adb4937c2481e6f3d677c7fae9314ae5ca1f 100644 (file)
@@ -96,7 +96,7 @@ static void print_status_info(const StatusInfo *i) {
                 old_tz = strdupa(tz);
 
         /* Set the new $TZ */
-        if (setenv("TZ", i->timezone, true) < 0)
+        if (i->timezone && setenv("TZ", i->timezone, true) < 0)
                 log_warning_errno(errno, "Failed to set TZ environment variable, ignoring: %m");
         else
                 tzset();