From owner-svn-src-head@freebsd.org Thu Jul 20 15:28:50 2017 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 02897C7A69F; Thu, 20 Jul 2017 15:28:50 +0000 (UTC) (envelope-from emaste@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id C0AEA6D505; Thu, 20 Jul 2017 15:28:49 +0000 (UTC) (envelope-from emaste@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v6KFSmnc088614; Thu, 20 Jul 2017 15:28:48 GMT (envelope-from emaste@FreeBSD.org) Received: (from emaste@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v6KFSmGR088613; Thu, 20 Jul 2017 15:28:48 GMT (envelope-from emaste@FreeBSD.org) Message-Id: <201707201528.v6KFSmGR088613@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: emaste set sender to emaste@FreeBSD.org using -f From: Ed Maste Date: Thu, 20 Jul 2017 15:28:48 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r321293 - head/bin/date X-SVN-Group: head X-SVN-Commit-Author: emaste X-SVN-Commit-Paths: head/bin/date X-SVN-Commit-Revision: 321293 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 20 Jul 2017 15:28:50 -0000 Author: emaste Date: Thu Jul 20 15:28:48 2017 New Revision: 321293 URL: https://svnweb.freebsd.org/changeset/base/321293 Log: date: avoid crash on invalid time localtime(3) returns NULL when passed an invalid time_t but date(1) previously did not handle it. Exit with an error in that case. PR: 220828 Reported by: Vinícius Zavam Reviewed by: cem, kevans Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D11660 Modified: head/bin/date/date.c Modified: head/bin/date/date.c ============================================================================== --- head/bin/date/date.c Thu Jul 20 14:50:13 2017 (r321292) +++ head/bin/date/date.c Thu Jul 20 15:28:48 2017 (r321293) @@ -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 = 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, <); + (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) {