aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRich Felker <dalias@aerifal.cx>2017-06-15 12:58:08 -0400
committerRich Felker <dalias@aerifal.cx>2017-06-15 12:58:08 -0400
commit5c10c33d2a35204ee76931625a007fcc8cca3228 (patch)
tree8847a78536f72c9c062ad5cd2bedc6fd4ae79ee4
parenthandle mremap failure in realloc of mmap-serviced allocations (diff)
downloadgrovel-5c10c33d2a35204ee76931625a007fcc8cca3228.tar.gz
grovel-5c10c33d2a35204ee76931625a007fcc8cca3228.tar.xz
handle localtime errors in ctime
ctime passes the result from localtime directly to asctime. But in case of error, localtime returns 0. This causes an error (NULL pointer dereference) in asctime. based on patch by Omer Anson.
-rw-r--r--src/time/ctime.c4
1 files changed, 3 insertions, 1 deletions
diff --git a/src/time/ctime.c b/src/time/ctime.c
index 185ec554..36029315 100644
--- a/src/time/ctime.c
+++ b/src/time/ctime.c
@@ -2,5 +2,7 @@
char *ctime(const time_t *t)
{
- return asctime(localtime(t));
+ struct tm *tm = localtime(t);
+ if (!tm) return 0;
+ return asctime(tm);
}