Fixes, from Scott Renfro, for some calls to "localtime()" that didn't
authorguy <guy@f5534014-38df-0310-8fa8-9805f1628bb7>
Sun, 15 Jul 2001 19:14:03 +0000 (19:14 +0000)
committerguy <guy@f5534014-38df-0310-8fa8-9805f1628bb7>
Sun, 15 Jul 2001 19:14:03 +0000 (19:14 +0000)
check whether the call succeeded (it doesn't always do so on Windows,
for example).

git-svn-id: http://anonsvn.wireshark.org/wireshark/trunk@3722 f5534014-38df-0310-8fa8-9805f1628bb7

AUTHORS
epan/column-utils.c
epan/to_str.c
packet-diameter.c
packet-ntp.c
packet-srvloc.c
wiretap/netmon.c
wiretap/ngsniffer.c

diff --git a/AUTHORS b/AUTHORS
index d4916b1edf9d0a7153b15be7144415c4dbfabbb5..5a93f79c1c078a8367eab7d57152b5590be9389d 100644 (file)
--- a/AUTHORS
+++ b/AUTHORS
@@ -646,6 +646,9 @@ Scott Renfro <scott@renfro.org> {
        "-t" flag for editcap, to adjust timestamps in frames
        SSL/TLS support
        Mergecap utility for merging capture files
+       Fixes for some calls to "localtime()" that didn't check whether
+          the call succeeded (it doesn't always do so on Windows, for
+          example)
 }
 
 Juan Toledo <toledo@users.sourceforge.net> {
index 3a44cf66babf2750d4b1f7cc6f59f8941137de61..15c8776a8917869f3ac1b1cbe709672e81d0f26a 100644 (file)
@@ -1,7 +1,7 @@
 /* column-utils.c
  * Routines for column utilities.
  *
- * $Id: column-utils.c,v 1.3 2001/04/02 10:38:26 guy Exp $
+ * $Id: column-utils.c,v 1.4 2001/07/15 19:14:02 guy Exp $
  *
  * Ethereal - Network traffic analyzer
  * By Gerald Combs <gerald@zing.org>
@@ -248,15 +248,19 @@ col_set_abs_date_time(frame_data *fd, int col)
 
   then = fd->abs_secs;
   tmp = localtime(&then);
-  snprintf(fd->cinfo->col_buf[col], COL_MAX_LEN,
-    "%04d-%02d-%02d %02d:%02d:%02d.%04ld",
-    tmp->tm_year + 1900,
-    tmp->tm_mon + 1,
-    tmp->tm_mday,
-    tmp->tm_hour,
-    tmp->tm_min,
-    tmp->tm_sec,
-    (long)fd->abs_usecs/100);
+  if (tmp != NULL) {
+    snprintf(fd->cinfo->col_buf[col], COL_MAX_LEN,
+             "%04d-%02d-%02d %02d:%02d:%02d.%04ld",
+             tmp->tm_year + 1900,
+             tmp->tm_mon + 1,
+             tmp->tm_mday,
+             tmp->tm_hour,
+             tmp->tm_min,
+             tmp->tm_sec,
+             (long)fd->abs_usecs/100);
+  } else {
+    fd->cinfo->col_buf[col][0] = '\0';
+  }
   fd->cinfo->col_data[col] = fd->cinfo->col_buf[col];
 }
 
@@ -286,11 +290,15 @@ col_set_abs_time(frame_data *fd, int col)
 
   then = fd->abs_secs;
   tmp = localtime(&then);
-  snprintf(fd->cinfo->col_buf[col], COL_MAX_LEN, "%02d:%02d:%02d.%04ld",
-    tmp->tm_hour,
-    tmp->tm_min,
-    tmp->tm_sec,
-    (long)fd->abs_usecs/100);
+  if (tmp != NULL) {
+    snprintf(fd->cinfo->col_buf[col], COL_MAX_LEN, "%02d:%02d:%02d.%04ld",
+             tmp->tm_hour,
+             tmp->tm_min,
+             tmp->tm_sec,
+             (long)fd->abs_usecs/100);
+  } else {
+    fd->cinfo->col_buf[col][0] = '\0';
+  }
   fd->cinfo->col_data[col] = fd->cinfo->col_buf[col];
 }
 
index bbf8e97ed0f7e6b0ef0df28239b4dbfb72cf0ab8..26229c2be3d7ffbee60161d8345d1d2d13779fae 100644 (file)
@@ -1,7 +1,7 @@
 /* to_str.h
  * Routines  for utilities to convert various other types to strings.
  *
- * $Id: to_str.c,v 1.9 2001/07/13 00:27:51 guy Exp $
+ * $Id: to_str.c,v 1.10 2001/07/15 19:14:02 guy Exp $
  *
  * Ethereal - Network traffic analyzer
  * By Gerald Combs <gerald@zing.org>
@@ -411,15 +411,18 @@ abs_time_to_str(struct timeval *abs_time)
         }
 
         tmp = localtime(&abs_time->tv_sec);
-        sprintf(cur, "%s %2d, %d %02d:%02d:%02d.%06ld",
-            mon_names[tmp->tm_mon],
-            tmp->tm_mday,
-            tmp->tm_year + 1900,
-            tmp->tm_hour,
-            tmp->tm_min,
-            tmp->tm_sec,
-            (long)abs_time->tv_usec);
-
+        if (tmp) {
+          sprintf(cur, "%s %2d, %d %02d:%02d:%02d.%06ld",
+                  mon_names[tmp->tm_mon],
+                  tmp->tm_mday,
+                  tmp->tm_year + 1900,
+                  tmp->tm_hour,
+                  tmp->tm_min,
+                  tmp->tm_sec,
+                  (long)abs_time->tv_usec);
+        } else {
+          strncpy(cur, "Not representable", sizeof(str[0]));
+        }
         return cur;
 }
 
index 77a50cab08bb6faea1240246e7c4daa76ade3dae..4891518e74662d57d920e9f7df2452abde28345b 100644 (file)
@@ -1,7 +1,7 @@
 /* packet-diameter.c
  * Routines for DIAMETER packet disassembly
  *
- * $Id: packet-diameter.c,v 1.23 2001/06/18 02:17:45 guy Exp $
+ * $Id: packet-diameter.c,v 1.24 2001/07/15 19:14:00 guy Exp $
  *
  * Copyright (c) 2001 by David Frascone <dave@frascone.com>
  *
@@ -702,12 +702,16 @@ static gchar *rd_value_to_str(e_avphdr *avph, const u_char *input, int length)
 #endif
                case DIAMETER_TIME:
                {
-                       struct tm lt;
+                       struct tm *lt;
                        intval=pntohl(input);
                        intval -= NTP_TIME_DIFF;
-                       lt=*localtime((time_t *)&intval);
-                       strftime(buffer, 1024, 
-                           "%a, %d %b %Y %H:%M:%S %z",&lt);
+                       lt=localtime((time_t *)&intval);
+                       if (lt != NULL) {
+                         strftime(buffer, 1024, 
+                                  "%a, %d %b %Y %H:%M:%S %z",lt);
+                       } else {
+                         strncpy(buffer, "Not representable", 1024);
+                       }
                }
                default:
                        /* Do nothing */
index 7b7fa3c4d0bc1c6a3bce48945ca6d8549e800b69..37fbc5bbfe99112e4ed1f9857dc51202f8370c95 100644 (file)
@@ -2,7 +2,7 @@
  * Routines for NTP packet dissection
  * Copyright 1999, Nathan Neulinger <nneul@umr.edu>
  *
- * $Id: packet-ntp.c,v 1.28 2001/06/18 02:17:50 guy Exp $
+ * $Id: packet-ntp.c,v 1.29 2001/07/15 19:14:00 guy Exp $
  *
  * Ethereal - Network traffic analyzer
  * By Gerald Combs <gerald@zing.org>
@@ -236,10 +236,14 @@ ntp_fmt_ts(const guint8 *reftime, char* buff)
        } else {
                temptime = tempstmp - (guint32) NTP_BASETIME;
                bd = gmtime(&temptime);
-               fractime = bd->tm_sec + tempfrac / 4294967296.0;
-               snprintf(buff, NTP_TS_SIZE, "%04d-%02d-%02d %02d:%02d:%07.4f UTC",
-                        bd->tm_year + 1900, bd->tm_mon + 1, bd->tm_mday,
-                        bd->tm_hour, bd->tm_min, fractime);
+        if (bd != NULL) {
+          fractime = bd->tm_sec + tempfrac / 4294967296.0;
+          snprintf(buff, NTP_TS_SIZE, "%04d-%02d-%02d %02d:%02d:%07.4f UTC",
+                   bd->tm_year + 1900, bd->tm_mon + 1, bd->tm_mday,
+                   bd->tm_hour, bd->tm_min, fractime);
+        } else {
+          strncpy(buff, "Not representable", NTP_TS_SIZE);
+        }
        }
        return buff;
 }
index 1d0a3f4854999c009c1f2c447a4b8e00dc90dd6b..b4494eec87321be8fea66107a20ca1c0e9d0f84a 100644 (file)
@@ -6,7 +6,7 @@
  *       In particular I have not had an opportunity to see how it 
  *       responds to SRVLOC over TCP.
  *
- * $Id: packet-srvloc.c,v 1.24 2001/06/18 02:17:53 guy Exp $
+ * $Id: packet-srvloc.c,v 1.25 2001/07/15 19:14:00 guy Exp $
  *
  * Ethereal - Network traffic analyzer
  * By Gerald Combs <gerald@ethereal.com>
@@ -193,12 +193,16 @@ dissect_authblk(tvbuff_t *tvb, int offset, proto_tree *tree)
     
     seconds = tvb_get_ntohl(tvb, offset) - 2208988800ul;
     stamp = gmtime(&seconds);
-    floatsec = stamp->tm_sec + tvb_get_ntohl(tvb, offset + 4) / 4294967296.0;
-    proto_tree_add_text(tree, tvb, offset, 8,
-                       "Timestamp: %04d-%02d-%02d %02d:%02d:%07.4f UTC",
-                       stamp->tm_year + 1900, stamp->tm_mon + 1,
-                       stamp->tm_mday, stamp->tm_hour, stamp->tm_min,
-                       floatsec);
+    if (stamp != NULL) {
+      floatsec = stamp->tm_sec + tvb_get_ntohl(tvb, offset + 4) / 4294967296.0;
+      proto_tree_add_text(tree, tvb, offset, 8,
+                          "Timestamp: %04d-%02d-%02d %02d:%02d:%07.4f UTC",
+                          stamp->tm_year + 1900, stamp->tm_mon + 1,
+                          stamp->tm_mday, stamp->tm_hour, stamp->tm_min,
+                          floatsec);
+    } else {
+      proto_tree_add_text(tree, tvb, offset, 8, "Timestamp not representable");
+    }
     proto_tree_add_text(tree, tvb, offset + 8, 2, "Block Structure Desciptor: %u",
                        tvb_get_ntohs(tvb, offset + 8));
     length = tvb_get_ntohs(tvb, offset + 10);
index a0b489a71f53bce52c9124e48292f31a394c4465..d90f601155b6fdaca75f75975a3a6d007b1b2324 100644 (file)
@@ -1,6 +1,6 @@
 /* netmon.c
  *
- * $Id: netmon.c,v 1.38 2001/07/13 00:55:58 guy Exp $
+ * $Id: netmon.c,v 1.39 2001/07/15 19:14:03 guy Exp $
  *
  * Wiretap Library
  * Copyright (c) 1998 by Gilbert Ramirez <gram@xiexie.org>
@@ -635,14 +635,24 @@ static gboolean netmon_dump_close(wtap_dumper *wdh, int *err)
 
        file_hdr.network = htoles(wtap_encap[wdh->encap]);
        tm = localtime(&netmon->first_record_time.tv_sec);
-       file_hdr.ts_year = htoles(1900 + tm->tm_year);
-       file_hdr.ts_month = htoles(tm->tm_mon + 1);
-       file_hdr.ts_dow = htoles(tm->tm_wday);
-       file_hdr.ts_day = htoles(tm->tm_mday);
-       file_hdr.ts_hour = htoles(tm->tm_hour);
-       file_hdr.ts_min = htoles(tm->tm_min);
-       file_hdr.ts_sec = htoles(tm->tm_sec);
-       file_hdr.ts_msec = htoles(netmon->first_record_time.tv_usec/1000);
+    if (tm != NULL) {
+      file_hdr.ts_year  = htoles(1900 + tm->tm_year);
+      file_hdr.ts_month = htoles(tm->tm_mon + 1);
+      file_hdr.ts_dow   = htoles(tm->tm_wday);
+      file_hdr.ts_day   = htoles(tm->tm_mday);
+      file_hdr.ts_hour  = htoles(tm->tm_hour);
+      file_hdr.ts_min   = htoles(tm->tm_min);
+      file_hdr.ts_sec   = htoles(tm->tm_sec);
+    } else {
+      file_hdr.ts_year  = htoles(1900 + 0);
+      file_hdr.ts_month = htoles(0 + 1);
+      file_hdr.ts_dow   = htoles(0);
+      file_hdr.ts_day   = htoles(0);
+      file_hdr.ts_hour  = htoles(0);
+      file_hdr.ts_min   = htoles(0);
+      file_hdr.ts_sec   = htoles(0);
+    }      
+    file_hdr.ts_msec  = htoles(netmon->first_record_time.tv_usec/1000);
                /* XXX - what about rounding? */
        file_hdr.frametableoffset = htolel(netmon->frame_table_offset);
        file_hdr.frametablelength =
index 71b2f013d645047592a224cf29ca6172cb4f59ed..691db45107bf669331684f42fb19cdf044be99ee 100644 (file)
@@ -1,6 +1,6 @@
 /* ngsniffer.c
  *
- * $Id: ngsniffer.c,v 1.64 2001/07/06 00:17:36 guy Exp $
+ * $Id: ngsniffer.c,v 1.65 2001/07/15 19:14:03 guy Exp $
  *
  * Wiretap Library
  * Copyright (c) 1998 by Gilbert Ramirez <gram@xiexie.org>
@@ -1204,11 +1204,16 @@ static gboolean ngsniffer_dump(wtap_dumper *wdh, const struct wtap_pkthdr *phdr,
     if (priv->first_frame) {
        priv->first_frame=FALSE;
        tm = localtime(&phdr->ts.tv_sec);
-       start_date = (tm->tm_year - (1980 - 1900)) << 9;
-       start_date |= (tm->tm_mon + 1) << 5;
-       start_date |= tm->tm_mday;
-       /* record the start date, not the start time */
-       priv->start = phdr->ts.tv_sec - (3600*tm->tm_hour + 60*tm->tm_min + tm->tm_sec);
+       if (tm != NULL) {
+         start_date = (tm->tm_year - (1980 - 1900)) << 9;
+         start_date |= (tm->tm_mon + 1) << 5;
+         start_date |= tm->tm_mday;
+         /* record the start date, not the start time */
+         priv->start = phdr->ts.tv_sec - (3600*tm->tm_hour + 60*tm->tm_min + tm->tm_sec);
+       } else {
+         start_date = 0;
+         priv->start = 0;
+       }
 
        /* "sniffer" version ? */
        maj_vers = 4;