Mercurial > dropbear
diff svr-session.c @ 404:a588558bfc94
Fix potential null pointer dereference found by Klokwork
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Sat, 03 Feb 2007 09:58:14 +0000 |
parents | 3be7ae2e8dfa |
children | c216212001fc |
line wrap: on
line diff
--- a/svr-session.c Sat Feb 03 09:42:22 2007 +0000 +++ b/svr-session.c Sat Feb 03 09:58:14 2007 +0000 @@ -181,10 +181,15 @@ 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); }