ar: Assume epoch if ar_date is bogus.
authorMark Wielaard <mark@klomp.org>
Sun, 14 Oct 2018 15:29:51 +0000 (17:29 +0200)
committerMark Wielaard <mark@klomp.org>
Fri, 19 Oct 2018 22:13:09 +0000 (00:13 +0200)
If the ar header contains a bogus ar_date then in verbose mode we would
get a NULL pointer from localtime. Just assume the entry was created
during the epoch.

https://sourceware.org/bugzilla/show_bug.cgi?id=23754

Signed-off-by: Mark Wielaard <mark@klomp.org>
src/ChangeLog
src/ar.c

index d057669..40de5a0 100644 (file)
@@ -1,5 +1,9 @@
 2018-10-14  Mark Wielaard  <mark@klomp.org>
 
+       * ar.c (do_oper_extract): Assume epoch if ar_date is bogus.
+
+2018-10-14  Mark Wielaard  <mark@klomp.org>
+
        * findtextrel.c (process_file): Check that sh_entsize is not zero.
 
 2018-09-13  Mark Wielaard  <mark@klomp.org>
index 6f98f75..d70f1f4 100644 (file)
--- a/src/ar.c
+++ b/src/ar.c
@@ -539,8 +539,14 @@ do_oper_extract (int oper, const char *arfname, char **argv, int argc,
              else if (oper == oper_list)
                {
                  char datestr[100];
-                 strftime (datestr, sizeof (datestr), "%b %e %H:%M %Y",
-                           localtime (&arhdr->ar_date));
+                 struct tm *tp = localtime (&arhdr->ar_date);
+                 if (tp == NULL)
+                   {
+                     time_t time = 0;
+                     tp = localtime (&time);
+                   }
+
+                 strftime (datestr, sizeof (datestr), "%b %e %H:%M %Y", tp);
 
                  printf ("%c%c%c%c%c%c%c%c%c %u/%u %6ju %s %s\n",
                          (arhdr->ar_mode & S_IRUSR) ? 'r' : '-',