From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/11489 Path: news.gmane.org!.POSTED!not-for-mail From: Rich Felker Newsgroups: gmane.linux.lib.musl.general Subject: Re: [PATCH] Handle localtime errors in ctime Date: Thu, 15 Jun 2017 12:54:13 -0400 Message-ID: <20170615165413.GO1627@brightrain.aerifal.cx> References: <1497545016-22965-1-git-send-email-oaanson@gmail.com> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: blaine.gmane.org 1497545666 8228 195.159.176.226 (15 Jun 2017 16:54:26 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Thu, 15 Jun 2017 16:54:26 +0000 (UTC) User-Agent: Mutt/1.5.21 (2010-09-15) To: musl@lists.openwall.com Original-X-From: musl-return-11502-gllmg-musl=m.gmane.org@lists.openwall.com Thu Jun 15 18:54:23 2017 Return-path: Envelope-to: gllmg-musl@m.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by blaine.gmane.org with smtp (Exim 4.84_2) (envelope-from ) id 1dLY2I-0001wD-Sa for gllmg-musl@m.gmane.org; Thu, 15 Jun 2017 18:54:22 +0200 Original-Received: (qmail 7845 invoked by uid 550); 15 Jun 2017 16:54:25 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Original-Received: (qmail 7827 invoked from network); 15 Jun 2017 16:54:25 -0000 Content-Disposition: inline In-Reply-To: <1497545016-22965-1-git-send-email-oaanson@gmail.com> Original-Sender: Rich Felker Xref: news.gmane.org gmane.linux.lib.musl.general:11489 Archived-At: On Thu, Jun 15, 2017 at 07:43:36PM +0300, Omer Anson wrote: > 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 Content looks good. Making minor edits for style and I'll commit. Also please don't link to linux.die.net; the standard (C or POSIX), not the man page, is authoritative for things like this, and linux.die.net is pretty much just SEO spam (using outdated versions of scraped content, i.e. man pages, to boost pagerank). Rich