]> The Tcpdump Group git mirrors - tcpdump/commitdiff
"localtime()" can return a null pointer on Windows; if I remember
authorguy <guy>
Wed, 4 Sep 2002 09:53:42 +0000 (09:53 +0000)
committerguy <guy>
Wed, 4 Sep 2002 09:53:42 +0000 (09:53 +0000)
correctly, this can happen if the time handed to it is before the UNIX
epoch.  Just report "(Can't convert time)" if it returns a null pointer.

smbutil.c

index af237f1e04c952e7b312748cd15708b2afb60342..48e5116afb90f7b201bcff6ad0ccc0403d774eee 100644 (file)
--- a/smbutil.c
+++ b/smbutil.c
@@ -12,7 +12,7 @@
 
 #ifndef lint
 static const char rcsid[] =
-     "@(#) $Header: /tcpdump/master/tcpdump/smbutil.c,v 1.23 2002-08-06 04:42:07 guy Exp $";
+     "@(#) $Header: /tcpdump/master/tcpdump/smbutil.c,v 1.24 2002-09-04 09:53:42 guy Exp $";
 #endif
 
 #include <tcpdump-stdinc.h>
@@ -572,6 +572,8 @@ smb_fdata1(const u_char *buf, const char *fmt, const u_char *maxbuf)
        case 'T':
          {
            time_t t;
+           struct tm *lt;
+           char *tstring;
            int x;
            x = EXTRACT_LE_32BITS(buf);
 
@@ -595,7 +597,15 @@ smb_fdata1(const u_char *buf, const char *fmt, const u_char *maxbuf)
                buf += 8;
                break;
            }
-           printf("%s", t ? asctime(localtime(&t)) : "NULL\n");
+           if (t != 0) {
+               lt = localtime(&t);
+               if (lt != NULL)
+                   tstring = asctime(lt);
+               else
+                   tstring = "(Can't convert time)\n";
+           } else
+               tstring = "NULL\n";
+           printf("%s", tstring);
            fmt++;
            while (isdigit((unsigned char)*fmt))
                fmt++;