aboutsummaryrefslogtreecommitdiffstats
path: root/main/musl/0046-handle-localtime-errors-in-ctime.patch
blob: 00a4dce65e7bc798cf00ab876f6857b8d2ee2668 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
From 5c10c33d2a35204ee76931625a007fcc8cca3228 Mon Sep 17 00:00:00 2001
From: Rich Felker <dalias@aerifal.cx>
Date: Thu, 15 Jun 2017 12:58:08 -0400
Subject: [PATCH] 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.
---
 src/time/ctime.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

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);
 }
-- 
2.13.0