public inbox for elfutils@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] ar: Assume epoch if ar_date is bogus.
@ 2018-10-14 15:31 Mark Wielaard
  2018-10-19 22:28 ` Mark Wielaard
  0 siblings, 1 reply; 2+ messages in thread
From: Mark Wielaard @ 2018-10-14 15:31 UTC (permalink / raw)
  To: elfutils-devel; +Cc: Mark Wielaard

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 |  4 ++++
 src/ar.c      | 10 ++++++++--
 2 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/src/ChangeLog b/src/ChangeLog
index b260044..8fb3deb 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -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-10-02  Andreas Schwab  <schwab@suse.de>
diff --git a/src/ar.c b/src/ar.c
index 6f98f75..d70f1f4 100644
--- 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' : '-',
-- 
1.8.3.1

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] ar: Assume epoch if ar_date is bogus.
  2018-10-14 15:31 [PATCH] ar: Assume epoch if ar_date is bogus Mark Wielaard
@ 2018-10-19 22:28 ` Mark Wielaard
  0 siblings, 0 replies; 2+ messages in thread
From: Mark Wielaard @ 2018-10-19 22:28 UTC (permalink / raw)
  To: elfutils-devel

On Sun, 2018-10-14 at 17:31 +0200, Mark Wielaard wrote:
> 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.

Pushed to master.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2018-10-19 22:28 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-10-14 15:31 [PATCH] ar: Assume epoch if ar_date is bogus Mark Wielaard
2018-10-19 22:28 ` Mark Wielaard

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).