summaryrefslogtreecommitdiff
path: root/wiretap
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>2017-04-17 11:02:49 -0700
committerGuy Harris <guy@alum.mit.edu>2017-04-17 18:03:46 +0000
commit25382fd638a7152d0262b994b1b1b38e9e1ae283 (patch)
treef9a6d0de6e9d0a5d5b6a4da7eb439c198b7c40f8 /wiretap
parent07e2f65b9627f9b37648f4a9dd310d9e18bac223 (diff)
downloadwireshark-25382fd638a7152d0262b994b1b1b38e9e1ae283.tar.gz
Don't assume gmtime() or localtime() succeed.
The chances that they won't, in this case, are slim to none, as the time is after the Epoch, but this squelches CID 1398223. We'll change the master branch to require an err_info string for WTAP_ERR_INTERNAL and to display it in a future commit. Change-Id: Ifb51076b25117efc53ba3ad8b434e36c71f7600f Reviewed-on: https://code.wireshark.org/review/21169 Reviewed-by: Guy Harris <guy@alum.mit.edu>
Diffstat (limited to 'wiretap')
-rw-r--r--wiretap/network_instruments.c26
1 files changed, 22 insertions, 4 deletions
diff --git a/wiretap/network_instruments.c b/wiretap/network_instruments.c
index fb335f445c..f4c0cfad8b 100644
--- a/wiretap/network_instruments.c
+++ b/wiretap/network_instruments.c
@@ -70,10 +70,11 @@ typedef struct {
static const time_t ansi_to_observer_epoch_offset = 946684800;
static time_t gmt_to_localtime_offset = (time_t) -1;
-static void init_gmt_to_localtime_offset(void)
+static const char *init_gmt_to_localtime_offset(void)
{
if (gmt_to_localtime_offset == (time_t) -1) {
time_t ansi_epoch_plus_one_day = 86400;
+ struct tm *tm;
struct tm gmt_tm;
struct tm local_tm;
@@ -86,11 +87,18 @@ static void init_gmt_to_localtime_offset(void)
* back to time_t as if they were both local times, resulting in the
* time zone offset being the difference between them.
*/
- gmt_tm = *gmtime(&ansi_epoch_plus_one_day);
- local_tm = *localtime(&ansi_epoch_plus_one_day);
+ tm = gmtime(&ansi_epoch_plus_one_day);
+ if (tm == NULL)
+ return "gmtime(one day past the Epoch) fails (this \"shouldn't happen\")";
+ gmt_tm = *tm;
+ if (tm == NULL)
+ return "localtime(one day past the Epoch) fails (this \"shouldn't happen\")";
+ tm = localtime(&ansi_epoch_plus_one_day);
+ local_tm = *tm;
local_tm.tm_isdst = 0;
gmt_to_localtime_offset = mktime(&gmt_tm) - mktime(&local_tm);
}
+ return NULL;
}
static gboolean observer_read(wtap *wth, int *err, gchar **err_info,
@@ -237,7 +245,17 @@ wtap_open_return_val network_instruments_open(wtap *wth, int *err, gchar **err_i
if (file_seek(wth->fh, header_offset, SEEK_SET, err) == -1)
return WTAP_OPEN_ERROR;
- init_gmt_to_localtime_offset();
+ if (init_gmt_to_localtime_offset() != NULL) {
+ *err = WTAP_ERR_INTERNAL;
+ /*
+ * XXX - we should return the error string, so the caller
+ * can report the details of the internal error, but that
+ * would require plugin file readers to do so for internal
+ * errors as well, which could break binary compatibility;
+ * we'll do that in the next release.
+ */
+ return WTAP_OPEN_ERROR;
+ }
return WTAP_OPEN_MINE;
}