Index: shadow-4.5/src/chage.c
===================================================================
--- a/src/chage.c
+++ b/src/chage.c
@@ -167,6 +167,10 @@ static void date_to_str (char *buf, size_t maxsize, time_t date)
 	struct tm *tp;
 
 	tp = gmtime (&date);
+	if (tp == NULL) {
+		(void) snprintf (buf, maxsize, "(unknown)");
+		return;
+	}
 #ifdef HAVE_STRFTIME
 	(void) strftime (buf, maxsize, "%Y-%m-%d", tp);
 #else
Index: shadow-4.5/src/faillog.c
===================================================================
--- a/src/faillog.c
+++ b/src/faillog.c
@@ -163,10 +163,14 @@ static void print_one (/*@null@*/const struct passwd *pw, bool force)
 	}
 
 	tm = localtime (&fl.fail_time);
+	if (tm == NULL) {
+		cp = "(unknown)";
+	} else {
 #ifdef HAVE_STRFTIME
-	strftime (ptime, sizeof (ptime), "%D %H:%M:%S %z", tm);
-	cp = ptime;
+		strftime (ptime, sizeof (ptime), "%D %H:%M:%S %z", tm);
+		cp = ptime;
 #endif
+	}
 	printf ("%-9s   %5d    %5d   ",
 	        pw->pw_name, fl.fail_cnt, fl.fail_max);
 	/* FIXME: cp is not defined ifndef HAVE_STRFTIME */
Index: shadow-4.5/src/lastlog.c
===================================================================
--- a/src/lastlog.c
+++ b/src/lastlog.c
@@ -159,13 +159,17 @@ static void print_one (/*@null@*/const struct passwd *pw)
 
 	ll_time = ll.ll_time;
 	tm = localtime (&ll_time);
+	if (tm == NULL) {
+		cp = "(unknown)";
+	} else {
 #ifdef HAVE_STRFTIME
-	strftime (ptime, sizeof (ptime), "%a %b %e %H:%M:%S %z %Y", tm);
-	cp = ptime;
+		strftime (ptime, sizeof (ptime), "%a %b %e %H:%M:%S %z %Y", tm);
+		cp = ptime;
 #else
-	cp = asctime (tm);
-	cp[24] = '\0';
+		cp = asctime (tm);
+		cp[24] = '\0';
 #endif
+	}
 
 	if (ll.ll_time == (time_t) 0) {
 		cp = _("**Never logged in**\0");
Index: shadow-4.5/src/passwd.c
===================================================================
--- a/src/passwd.c
+++ b/src/passwd.c
@@ -456,6 +456,9 @@ static /*@observer@*/const char *date_to_str (time_t t)
 	struct tm *tm;
 
 	tm = gmtime (&t);
+	if (tm == NULL) {
+		return "(unknown)";
+	}
 #ifdef HAVE_STRFTIME
 	(void) strftime (buf, sizeof buf, "%m/%d/%Y", tm);
 #else				/* !HAVE_STRFTIME */
Index: shadow-4.5/src/usermod.c
===================================================================
--- a/src/usermod.c
+++ b/src/usermod.c
@@ -216,6 +216,10 @@ static void date_to_str (/*@unique@*//*@out@*/char *buf, size_t maxsize,
 	} else {
 		time_t t = (time_t) date;
 		tp = gmtime (&t);
+		if (tp == NULL) {
+			strncpy (buf, "unknown", maxsize);
+			return;
+		}
 #ifdef HAVE_STRFTIME
 		strftime (buf, maxsize, "%Y-%m-%d", tp);
 #else
-- 
2.19.1

