mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Rich Felker <dalias@libc.org>
To: musl@lists.openwall.com
Subject: Re: [PATCH] Handle localtime errors in ctime
Date: Thu, 15 Jun 2017 12:54:13 -0400	[thread overview]
Message-ID: <20170615165413.GO1627@brightrain.aerifal.cx> (raw)
In-Reply-To: <1497545016-22965-1-git-send-email-oaanson@gmail.com>

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


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

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-06-15 16:43 Omer Anson
2017-06-15 16:54 ` Rich Felker [this message]
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=20170615165413.GO1627@brightrain.aerifal.cx \
    --to=dalias@libc.org \
    --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).