A NetBSD user reported fsck dumping core (when attempting to
correct a corrupted filesystem). That's not nice.
Upon investigation, the core dump turns out to be from within
asctime_r() (as called via asctime() from ctime()).
The code in fsck just does
p = ctime(&t);
where "t" contains one of the time fields from an (already
determined to be corrupted, or we wouldn't be printing) inode.
ctime() is (or course) just asctime(locatime(t))
locatime() can return NULL these days, and given a nonsense time
value (which is quite likely under these circumstances), probably did,
but asctime() doesn't expect anything but a valus "struct tm *" and will
simply dereference NULL is NULL is returned from localtime() - instant core.
It would be possible to make ctime() be
tm = localtime(t);
if (tm == NULL)
return NULL;
return asctime(tm);
and in theory that would be adequate, but I'm actually going to suggest
moving the fix into asctime() (into asctime_r() really of course), and
have asctime_r() start
if (timeptr == NULL)
return NULL;
I think that's a safer fix. Appended is the patch I suggest, made
against the tzcode2009t sources (latest I believe.)
kre