svn commit: r323044 - stable/11/bin/date
Ed Maste
emaste at FreeBSD.org
Thu Aug 31 02:37:46 UTC 2017
Author: emaste
Date: Thu Aug 31 02:37:44 2017
New Revision: 323044
URL: https://svnweb.freebsd.org/changeset/base/323044
Log:
MFC r321293: 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
Submitted by: Vinícius Zavam
Modified:
stable/11/bin/date/date.c
Directory Properties:
stable/11/ (props changed)
Modified: stable/11/bin/date/date.c
==============================================================================
--- stable/11/bin/date/date.c Thu Aug 31 00:56:10 2017 (r323043)
+++ stable/11/bin/date/date.c Thu Aug 31 02:37:44 2017 (r323044)
@@ -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) {
More information about the svn-src-stable
mailing list