From: Isaac Dunham <ibid.ag@gmail.com>
To: util-linux@vger.kernel.org
Cc: Isaac Dunham <ibid.ag@gmail.com>
Subject: [PATCH] hwclock: avoid UB if TZUTC is unset; include sys/time.h for timeval
Date: Wed, 22 Apr 2015 21:49:52 -0700 [thread overview]
Message-ID: <1429764592-15947-1-git-send-email-ibid.ag@gmail.com> (raw)
Fix a crash reported by Jean-Marc Pigeon on the musl mailing list.
If TZUTC is unset, setenv() will be called with value = NULL,
which invokes undefined behavior.
With musl libc, this causes a crash.
On uclibc and glibc, this currently happens to act like the long form
here, but glibc will make this an error:
https://sourceware.org/ml/libc-alpha/2015-03/threads.html#00449
Additionally, include <sys/time.h> to define struct timeval.
---
sys-utils/hwclock.c | 5 ++++-
sys-utils/hwclock.h | 1 +
2 files changed, 5 insertions(+), 1 deletion(-)
diff --git a/sys-utils/hwclock.c b/sys-utils/hwclock.c
index e1e5816..67971f0 100644
--- a/sys-utils/hwclock.c
+++ b/sys-utils/hwclock.c
@@ -408,7 +408,10 @@ mktime_tz(struct tm tm, const bool universal,
* libc's:
* TZUTC=:/usr/share/zoneinfo/right/UTC
*/
- setenv("TZ", getenv("TZUTC"), TRUE);
+ char *tzutc;
+
+ tzutc = getenv("TZUTC");
+ setenv("TZ", tzutc ? tzutc : "", TRUE);
/*
* Note: tzset() gets called implicitly by the time code,
* but only the first time. When changing the environment
diff --git a/sys-utils/hwclock.h b/sys-utils/hwclock.h
index 974d96a..7f19c39 100644
--- a/sys-utils/hwclock.h
+++ b/sys-utils/hwclock.h
@@ -6,6 +6,7 @@
#include <stdlib.h>
#include <string.h>
#include <time.h>
+#include <sys/time.h>
#include "c.h"
--
2.3.5
next reply other threads:[~2015-04-23 4:50 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-04-23 4:49 Isaac Dunham [this message]
2015-04-23 23:45 ` [PATCH 0/1] hwclock: Remove TZUTC J William Piggott
2015-04-23 23:53 ` [PATCH 1/1] " J William Piggott
2015-04-27 8:07 ` Karel Zak
2015-04-24 4:26 ` [PATCH 0/1] " Isaac Dunham
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1429764592-15947-1-git-send-email-ibid.ag@gmail.com \
--to=ibid.ag@gmail.com \
--cc=util-linux@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox