Mail archive

Re: [alpine-devel] Segfault in hwclock

From: Timo Teras <>
Date: Thu, 10 Apr 2014 09:11:16 +0300

On Wed, 9 Apr 2014 17:16:14 -0500
Jeff Pohlmeyer <> wrote:

> The "hwclock" program from util-linux is crashing with musl.

Committed a fix.

> The problem is on line 393 of util-linux-2.23.2/sys-utils/hwclock.c:
> setenv("TZ", getenv("TZUTC"), TRUE);
> Apparently musl's version of setenv() doesn't like it when the second
> argument is NULL.

Correct. This is per posix specification. value needs to point to a
valid string. This is application code bug.

> Compiling with gcc -Wall on ArchLinux/GNU-libc, I get a warning:
> warning: null argument where non-null required (argument 2)
> [-Wnonnull]

This is implies that glibc thinks same way. value must not be null. The
attribute also allows compiler to assume this and optimize code
accordingly. It would be perfectly valid for gcc to optimize glibc
build in such a way that it would crash too.

> But the program doesn't crash at run time.

Depends on compiler.

> With Alpine/musl, there is no compile time warning, but the program
> crashes.
> So it looks like musl's setenv() could stand to be a bit more robust,
> but hwclock
> really shouldn't be passing it a null, either.

Fixed application.

Thanks for the report.

- Timo

Received on Thu Apr 10 2014 - 09:11:16 UTC