OSDN Git Service

Fix hwclock -u.
authorElliott Hughes <enh@google.com>
Sat, 9 Jan 2016 20:20:50 +0000 (12:20 -0800)
committerRob Landley <rob@landley.net>
Mon, 11 Jan 2016 03:19:48 +0000 (21:19 -0600)
You can't pass a NULL value to setenv(3). The "put things back how they were"
intent of this code is best achieved by calling unsetenv(3) in the NULL case.

(This causes a crash with "hwclock -u" on Android. glibc silently corrupts the
environment instead.)

lib/xwrap.c

index 09f9197..a20d4b6 100644 (file)
@@ -704,13 +704,13 @@ void xregcomp(regex_t *preg, char *regex, int cflags)
 
 char *xtzset(char *new)
 {
-  char *tz = getenv("TZ");
+  char *old = getenv("TZ");
 
-  if (tz) tz = xstrdup(tz);
-  if (setenv("TZ", new, 1)) perror_exit("setenv");
+  if (old) old = xstrdup(old);
+  if (new ? setenv("TZ", new, 1) : unsetenv("TZ")) perror_exit("setenv");
   tzset();
 
-  return tz;
+  return old;
 }
 
 // Set a signal handler