diff options
author | marius <marius@FreeBSD.org> | 2017-09-07 23:28:35 +0000 |
---|---|---|
committer | marius <marius@FreeBSD.org> | 2017-09-07 23:28:35 +0000 |
commit | d014d3453df98ac0a22f7a78147ae516fd5847f8 (patch) | |
tree | e77d4bab585f1d693e4af33d97359f4d7279e1a0 | |
parent | cec050ba26dc8cd492c6c67a1ee9cc237129c281 (diff) | |
download | FreeBSD-src-d014d3453df98ac0a22f7a78147ae516fd5847f8.zip FreeBSD-src-d014d3453df98ac0a22f7a78147ae516fd5847f8.tar.gz |
MFC: r321293
date: avoid crash on invalid time
PR: 220828
Approved by: re (kib)
-rw-r--r-- | bin/date/date.c | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/bin/date/date.c b/bin/date/date.c index 9ae6502..c391901 100644 --- a/bin/date/date.c +++ b/bin/date/date.c @@ -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 nflag) int century; lt = localtime(&tval); + if (lt == NULL) + errx(1, "invalid time"); lt->tm_isdst = -1; /* divine correct DST */ if (fmt != NULL) { |