[B.A.T.M.A.N.] [PATCH 01/10] batctl: Print dummy value when localtime failed

Sven Eckelmann
2017-11-23T14:04:35Z

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(-)

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;
}

--
2.11.0