Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 7 Sep 2017 23:28:36 +0000 (UTC)
From:      Marius Strobl <marius@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org
Subject:   svn commit: r323291 - stable/10/bin/date
Message-ID:  <201709072328.v87NSapG000791@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: marius
Date: Thu Sep  7 23:28:35 2017
New Revision: 323291
URL: https://svnweb.freebsd.org/changeset/base/323291

Log:
  MFC: r321293
  
  date: avoid crash on invalid time
  
  PR:		220828
  Approved by:	re (kib)

Modified:
  stable/10/bin/date/date.c
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/bin/date/date.c
==============================================================================
--- stable/10/bin/date/date.c	Thu Sep  7 21:43:39 2017	(r323290)
+++ stable/10/bin/date/date.c	Thu Sep  7 23:28:35 2017	(r323291)
@@ -85,7 +85,7 @@ main(int argc, char *argv[])
 	int set_timezone;
 	struct vary *v;
 	const struct vary *badv;
-	struct tm lt;
+	struct tm *lt;
 	struct stat sb;
 
 	v = NULL;
@@ -174,8 +174,10 @@ main(int argc, char *argv[])
 	if (*argv && **argv == '+')
 		format = *argv + 1;
 
-	lt = *localtime(&tval);
-	badv = vary_apply(v, &lt);
+	lt = localtime(&tval);
+	if (lt == NULL)
+		errx(1, "invalid time");
+	badv = vary_apply(v, lt);
 	if (badv) {
 		fprintf(stderr, "%s: Cannot apply date adjustment\n",
 			badv->arg);
@@ -191,7 +193,7 @@ main(int argc, char *argv[])
 		 */
 		setlocale(LC_TIME, "C");
 
-	(void)strftime(buf, sizeof(buf), format, &lt);
+	(void)strftime(buf, sizeof(buf), format, lt);
 	(void)printf("%s\n", buf);
 	if (fflush(stdout))
 		err(1, "stdout");
@@ -210,6 +212,8 @@ setthetime(const char *fmt, const char *p, int jflag, 
 	int century;
 
 	lt = localtime(&tval);
+	if (lt == NULL)
+		errx(1, "invalid time");
 	lt->tm_isdst = -1;		/* divine correct DST */
 
 	if (fmt != NULL) {



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201709072328.v87NSapG000791>