[01/10] batctl: Print dummy value when localtime failed

Message ID 20171123140444.17119-2-sven.eckelmann@openmesh.com (mailing list archive)
State Accepted, archived
Commit 09dd2dc0b4945c83bd07ad4bce64062239d901fb
Delegated to: Simon Wunderlich
Headers
Series batctl: Fixes and minor cleanup |

Commit Message

Sven Eckelmann Nov. 23, 2017, 2:04 p.m. UTC
  localtime can return NULL when the local time could not be calculated.
Accessing this NULL pointer is not allowed.

Fixes: 05f27bfcd302 ("add arp packets , change output")
Signed-off-by: Sven Eckelmann <sven.eckelmann@openmesh.com>
---
 tcpdump.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
  

Patch

diff --git a/tcpdump.c b/tcpdump.c
index 4ede76b..5eb99cf 100644
--- a/tcpdump.c
+++ b/tcpdump.c
@@ -104,7 +104,11 @@  static int print_time(void)
 	gettimeofday(&tv, NULL);
 	tm = localtime(&tv.tv_sec);
 
-	printf("%02d:%02d:%02d.%06ld ", tm->tm_hour, tm->tm_min, tm->tm_sec, tv.tv_usec);
+	if (tm)
+		printf("%02d:%02d:%02d.%06ld ", tm->tm_hour, tm->tm_min, tm->tm_sec, tv.tv_usec);
+	else
+		printf("00:00:00.000000 ");
+
 	return 1;
 }