diff options
author | Guy Harris <guy@alum.mit.edu> | 2017-04-17 22:31:53 -0700 |
---|---|---|
committer | Guy Harris <guy@alum.mit.edu> | 2017-04-18 05:32:25 +0000 |
commit | 613476fbaf26bdcc427e661b4144f226b3319abd (patch) | |
tree | 2fefef2b3b8dce6571e14554b075d7b9e9fc8464 /wiretap | |
parent | 85d08e58cc9be2127dfa022cf3fab32e402f04f4 (diff) | |
download | wireshark-613476fbaf26bdcc427e661b4144f226b3319abd.tar.gz |
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 <guy@alum.mit.edu>
Diffstat (limited to 'wiretap')
-rw-r--r-- | wiretap/network_instruments.c | 24 |
1 files changed, 15 insertions, 9 deletions
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; |