aboutsummaryrefslogtreecommitdiff
path: root/lib/xwrap.c
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2016-01-09 12:20:50 -0800
committerRob Landley <rob@landley.net>2016-01-10 21:19:48 -0600
commitc55d30d85f1332f5022132c119ecfa3f2f16f4c5 (patch)
tree7516ef0fad09b930de963e0db52bfbf251beeb31 /lib/xwrap.c
parente8943589a8404b96071eb1890d08d3c80941fae8 (diff)
downloadtoybox-c55d30d85f1332f5022132c119ecfa3f2f16f4c5.tar.gz
Fix hwclock -u.
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.)
Diffstat (limited to 'lib/xwrap.c')
-rw-r--r--lib/xwrap.c8
1 files changed, 4 insertions, 4 deletions
diff --git a/lib/xwrap.c b/lib/xwrap.c
index 09f9197d..a20d4b6b 100644
--- a/lib/xwrap.c
+++ b/lib/xwrap.c
@@ -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