* [PATCH] hwclock: avoid UB if TZUTC is unset; include sys/time.h for timeval
@ 2015-04-23 4:49 Isaac Dunham
2015-04-23 23:45 ` [PATCH 0/1] hwclock: Remove TZUTC J William Piggott
0 siblings, 1 reply; 5+ messages in thread
From: Isaac Dunham @ 2015-04-23 4:49 UTC (permalink / raw)
To: util-linux; +Cc: Isaac Dunham
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
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 0/1] hwclock: Remove TZUTC
2015-04-23 4:49 [PATCH] hwclock: avoid UB if TZUTC is unset; include sys/time.h for timeval Isaac Dunham
@ 2015-04-23 23:45 ` J William Piggott
2015-04-23 23:53 ` [PATCH 1/1] " J William Piggott
2015-04-24 4:26 ` [PATCH 0/1] " Isaac Dunham
0 siblings, 2 replies; 5+ messages in thread
From: J William Piggott @ 2015-04-23 23:45 UTC (permalink / raw)
To: Karel Zak, Isaac Dunham; +Cc: util-linux
The patch that introduced TZUTC should have been rejected.
Mr. Parmelee misunderstood how to use and configure the
zoneinfo 'right' database. This was likely due to the 'right'
database being undocumented. I added information about the
database to the hwclock(8) man-page, and intended to remove
the TZUTC environment variable from hwclock when refactoring.
Since this regression needs to be addressed, it might as well
be removed now.
TZUTC is undocumented and should be safe to remove.
The following changes since commit e2381bdac86bb5fc27fe12ff9994268ea68888dc:
tests: fix sfdisk GPT test (2015-04-23 15:08:26 +0200)
are available in the git repository at:
git@github.com:jwpi/util-linux.git 423
for you to fetch changes up to 6b32ffc5f04869da3f8b4460f216e320df0f911a:
hwclock: Remove TZUTC (2015-04-23 16:26:25 -0400)
----------------------------------------------------------------
J William Piggott (1):
hwclock: Remove TZUTC
sys-utils/hwclock.c | 11 ++---------
1 file changed, 2 insertions(+), 9 deletions(-)
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 1/1] hwclock: Remove TZUTC
2015-04-23 23:45 ` [PATCH 0/1] hwclock: Remove TZUTC J William Piggott
@ 2015-04-23 23:53 ` J William Piggott
2015-04-27 8:07 ` Karel Zak
2015-04-24 4:26 ` [PATCH 0/1] " Isaac Dunham
1 sibling, 1 reply; 5+ messages in thread
From: J William Piggott @ 2015-04-23 23:53 UTC (permalink / raw)
To: Karel Zak, Isaac Dunham; +Cc: util-linux
commit d53f8ecfbf036eddb2aef737dc0973a613d80ced
introduced the TZUTC environment variable to
facilitate use of the zoneinfo 'right' database.
This was incorrect. Either the TZDIR environment
variable should be used or a system-wide
configuration for the 'right' database should be
used.
See hwclock(8) POSIX vs 'RIGHT' for more details.
TZUTC was undocumented and should be safe to remove.
The commit also caused a regression when using
musl libc, because when TZUTC is unset getenv()
returns a NULL pointer.
Reported-by: Isaac Dunham <ibid.ag@gmail.com>
Signed-off-by: J William Piggott <elseifthen@gmx.com>
---
sys-utils/hwclock.c | 11 ++---------
1 file changed, 2 insertions(+), 9 deletions(-)
diff --git a/sys-utils/hwclock.c b/sys-utils/hwclock.c
index e1e5816..f4784a1 100644
--- a/sys-utils/hwclock.c
+++ b/sys-utils/hwclock.c
@@ -400,15 +400,8 @@ mktime_tz(struct tm tm, const bool universal,
*/
zone = getenv("TZ"); /* remember original time zone */
if (universal) {
- /* Set timezone to UTC as defined by the environment
- * variable TZUTC. TZUTC undefined gives the default UTC
- * zonefile which usually does not take into account leap
- * seconds. Define TZUTC to select your UTC zonefile which
- * does include leap seconds. For example, with recent GNU
- * libc's:
- * TZUTC=:/usr/share/zoneinfo/right/UTC
- */
- setenv("TZ", getenv("TZUTC"), TRUE);
+ /* Set timezone to UTC */
+ setenv("TZ", "", TRUE);
/*
* Note: tzset() gets called implicitly by the time code,
* but only the first time. When changing the environment
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH 0/1] hwclock: Remove TZUTC
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-24 4:26 ` Isaac Dunham
1 sibling, 0 replies; 5+ messages in thread
From: Isaac Dunham @ 2015-04-24 4:26 UTC (permalink / raw)
To: J William Piggott; +Cc: Karel Zak, util-linux
On Thu, Apr 23, 2015 at 07:45:57PM -0400, J William Piggott wrote:
>
> The patch that introduced TZUTC should have been rejected.
> Mr. Parmelee misunderstood how to use and configure the
> zoneinfo 'right' database. This was likely due to the 'right'
> database being undocumented. I added information about the
> database to the hwclock(8) man-page, and intended to remove
> the TZUTC environment variable from hwclock when refactoring.
> Since this regression needs to be addressed, it might as well
> be removed now.
> TZUTC is undocumented and should be safe to remove.
>
Thanks.
This seems like the better fix.
Thank you,
Isaac Dunham
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH 1/1] hwclock: Remove TZUTC
2015-04-23 23:53 ` [PATCH 1/1] " J William Piggott
@ 2015-04-27 8:07 ` Karel Zak
0 siblings, 0 replies; 5+ messages in thread
From: Karel Zak @ 2015-04-27 8:07 UTC (permalink / raw)
To: J William Piggott; +Cc: Isaac Dunham, util-linux
On Thu, Apr 23, 2015 at 07:53:58PM -0400, J William Piggott wrote:
> sys-utils/hwclock.c | 11 ++---------
> 1 file changed, 2 insertions(+), 9 deletions(-)
Applied, thanks.
--
Karel Zak <kzak@redhat.com>
http://karelzak.blogspot.com
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2015-04-27 8:07 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-04-23 4:49 [PATCH] hwclock: avoid UB if TZUTC is unset; include sys/time.h for timeval Isaac Dunham
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
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox