From 613476fbaf26bdcc427e661b4144f226b3319abd Mon Sep 17 00:00:00 2001 From: Guy Harris Date: Mon, 17 Apr 2017 22:31:53 -0700 Subject: More checks for localtime() failing. Addresses CIDs 1398222 and 1398221. Fix the previous fix while we're at it. Change-Id: I6fe54e6ad115ac05154291b76de316426db72139 Reviewed-on: https://code.wireshark.org/review/21176 Reviewed-by: Guy Harris --- wiretap/network_instruments.c | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) (limited to 'wiretap') diff --git a/wiretap/network_instruments.c b/wiretap/network_instruments.c index f4c0cfad8b..a09d1b7f48 100644 --- a/wiretap/network_instruments.c +++ b/wiretap/network_instruments.c @@ -91,9 +91,9 @@ static const char *init_gmt_to_localtime_offset(void) if (tm == NULL) return "gmtime(one day past the Epoch) fails (this \"shouldn't happen\")"; gmt_tm = *tm; + tm = localtime(&ansi_epoch_plus_one_day); 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); @@ -505,6 +505,7 @@ process_packet_header(wtap *wth, packet_entry_header *packet_header, was captured while it was in effect */ if (((observer_dump_private_state*)wth->priv)->time_format == TIME_INFO_LOCAL) { + struct tm *tm; struct tm daylight_tm; struct tm standard_tm; time_t dst_offset; @@ -514,12 +515,15 @@ process_packet_header(wtap *wth, packet_entry_header *packet_header, phdr->ts.secs += gmt_to_localtime_offset; /* perform a DST adjustment if necessary */ - standard_tm = *localtime(&phdr->ts.secs); - if (standard_tm.tm_isdst > 0) { - daylight_tm = standard_tm; - standard_tm.tm_isdst = 0; - dst_offset = mktime(&standard_tm) - mktime(&daylight_tm); - phdr->ts.secs -= dst_offset; + tm = localtime(&phdr->ts.secs); + if (tm != NULL) { + standard_tm = *tm; + if (standard_tm.tm_isdst > 0) { + daylight_tm = standard_tm; + standard_tm.tm_isdst = 0; + dst_offset = mktime(&standard_tm) - mktime(&daylight_tm); + phdr->ts.secs -= dst_offset; + } } } @@ -632,10 +636,12 @@ gboolean network_instruments_dump_open(wtap_dumper *wdh, int *err) /* create the file comment TLV */ { time(&system_time); - /* We trusst the OS not to return a time before the Epoch */ current_time = localtime(&system_time); memset(&comment, 0x00, sizeof(comment)); - g_snprintf(comment, 64, "This capture was saved from Wireshark on %s", asctime(current_time)); + if (current_time != NULL) + g_snprintf(comment, 64, "This capture was saved from Wireshark on %s", asctime(current_time)); + else + g_snprintf(comment, 64, "This capture was saved from Wireshark"); comment_length = strlen(comment); comment_header.type = INFORMATION_TYPE_COMMENT; -- cgit v1.2.1