mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Omer Anson <oaanson@gmail.com>
To: musl@lists.openwall.com
Cc: Omer Anson <oaanson@gmail.com>
Subject: [PATCH] Handle localtime errors in ctime
Date: Thu, 15 Jun 2017 19:43:36 +0300	[thread overview]
Message-ID: <1497545016-22965-1-git-send-email-oaanson@gmail.com> (raw)

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



             reply	other threads:[~2017-06-15 16:43 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-06-15 16:43 Omer Anson [this message]
2017-06-15 16:54 ` Rich Felker
2017-06-15 17:03   ` Alexander Monakov
2017-06-15 17:06     ` Rich Felker
2017-06-15 17:19       ` Alexander Monakov
2017-06-15 17:26         ` Rich Felker
2017-06-15 17:31           ` Rich Felker
2017-06-15 17:46             ` Alexander Monakov
2017-06-21  0:34               ` Rich Felker
2017-06-21  7:18                 ` Alexander Monakov
2017-06-21 14:47                   ` Rich Felker

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1497545016-22965-1-git-send-email-oaanson@gmail.com \
    --to=oaanson@gmail.com \
    --cc=musl@lists.openwall.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).