|
Message-ID: <20170615165413.GO1627@brightrain.aerifal.cx> Date: Thu, 15 Jun 2017 12:54:13 -0400 From: Rich Felker <dalias@...c.org> To: musl@...ts.openwall.com Subject: Re: [PATCH] Handle localtime errors in ctime 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
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.