From 28f1026de851c17b2b0bfbefaf07e2f52e29ac4b Mon Sep 17 00:00:00 2001 From: Matt Johnston Date: Sat, 3 Feb 2007 09:58:14 +0000 Subject: [PATCH] Fix potential null pointer dereference found by Klokwork --HG-- extra : convert_revision : ef7030b29eca0944e6fbbdcdd776aafe39197ffa --- svr-session.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/svr-session.c b/svr-session.c index 70029f8..fe78bcc 100644 --- a/svr-session.c +++ b/svr-session.c @@ -181,10 +181,15 @@ void svr_dropbear_log(int priority, const char* format, va_list param) { if (!svr_opts.usingsyslog || havetrace) { + struct tm * local_tm = NULL; timesec = time(NULL); - if (strftime(datestr, sizeof(datestr), "%b %d %H:%M:%S", - localtime(×ec)) == 0) { - datestr[0] = '?'; datestr[1] = '\0'; + local_tm = localtime(×ec); + if (local_tm == NULL + || strftime(datestr, sizeof(datestr), "%b %d %H:%M:%S", + localtime(×ec)) == 0) + { + // upon failure, just print the epoch-seconds time. + snprintf(datestr, sizeof(datestr), "%d", timesec); } fprintf(stderr, "[%d] %s %s\n", getpid(), datestr, printbuf); }