From bd0bb36f431f4edb495133c5ffeec015ff5904e6 Mon Sep 17 00:00:00 2001 From: dougb Date: Sat, 5 Mar 2011 04:06:12 +0000 Subject: [PATCH] MFC r218535: Synthesize the change from NetBSD's 1.33: "Do not crash if a date cannot be represented (localtime returning NULL), use the Epoch value instead." Obtained from: njoly@NetBSD.org git-svn-id: svn://svn.freebsd.org/base/stable/8@219294 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f --- usr.bin/stat/stat.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/usr.bin/stat/stat.c b/usr.bin/stat/stat.c index b2ba03ff1..31e2bd957 100644 --- a/usr.bin/stat/stat.c +++ b/usr.bin/stat/stat.c @@ -30,7 +30,7 @@ #include #if 0 #ifndef lint -__RCSID("$NetBSD: stat.c,v 1.31 2010/12/16 05:30:16 dholland Exp $" +__RCSID("$NetBSD: stat.c,v 1.33 2011/01/15 22:54:10 njoly Exp $" "$OpenBSD: stat.c,v 1.14 2009/06/24 09:44:25 sobrado Exp $"); #endif #endif @@ -731,6 +731,10 @@ format1(const struct stat *st, small = (sizeof(ts.tv_sec) == 4); data = ts.tv_sec; tm = localtime(&ts.tv_sec); + if (tm == NULL) { + ts.tv_sec = 0; + tm = localtime(&ts.tv_sec); + } (void)strftime(path, sizeof(path), timefmt, tm); sdata = path; formats = FMTF_DECIMAL | FMTF_OCTAL | FMTF_UNSIGNED | FMTF_HEX | -- 2.45.0