Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <1497545016-22965-1-git-send-email-oaanson@gmail.com>
Date: Thu, 15 Jun 2017 19:43:36 +0300
From: Omer Anson <oaanson@...il.com>
To: musl@...ts.openwall.com
Cc: Omer Anson <oaanson@...il.com>
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.

According to the man pages [1], ctime should also return 0 upon error.
Therefore, if localtime fails (return 0), ctime also returns 0.

[1] https://linux.die.net/man/3/ctime
---
 src/time/ctime.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/src/time/ctime.c b/src/time/ctime.c
index 185ec55..6955f2d 100644
--- a/src/time/ctime.c
+++ b/src/time/ctime.c
@@ -2,5 +2,9 @@
 
 char *ctime(const time_t *t)
 {
-	return asctime(localtime(t));
+	struct tm * tm = localtime(t);
+	if (!tm) {
+		return 0;
+	}
+	return asctime(tm);
 }
-- 
2.4.11

Powered by blists - more mailing lists

Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.