From 219cf304c1a028f4010ba8868d6bd8f6ae70541d Mon Sep 17 00:00:00 2001 From: Jeff Morriss Date: Tue, 11 Nov 2014 15:22:12 -0500 Subject: Fix SMPP timestamp decoding when the current date/time's offset to UTC is different from the timestamp's offset to UTC. The fix for bug 6712 ignored the fact that daylight savings will affect the offset from UTC--and whether daylight savings is in effect today might be different than whether it was in effect in the timestamp we're decoding. Bug: 10672 Change-Id: Ie513c361cff41007f2328cd9ca9ca4800ffef500 Reviewed-on: https://code.wireshark.org/review/5245 Petri-Dish: Michael Mann Petri-Dish: Jeff Morriss Reviewed-by: Michael Mann --- epan/dissectors/packet-smpp.c | 35 ++++++++++++++++++----------------- 1 file changed, 18 insertions(+), 17 deletions(-) (limited to 'epan/dissectors/packet-smpp.c') diff --git a/epan/dissectors/packet-smpp.c b/epan/dissectors/packet-smpp.c index a067a02e5f..5bfac61b80 100644 --- a/epan/dissectors/packet-smpp.c +++ b/epan/dissectors/packet-smpp.c @@ -1180,34 +1180,35 @@ smpp_mktime(const char *datestr, time_t *secs, int *nsecs) if (relative == FALSE) { struct tm *gm, *local_time; int gm_hour, gm_min; - time_t current_time; *secs = mktime(&r_time); + *nsecs = (datestr[12] - '0') * 100000000; + + t_diff = (10 * (datestr[13] - '0') + (datestr[14] - '0')) * 900; + if (datestr[15] == '-') + /* Represented time is behind UTC, shift it forward to UTC */ + *secs += t_diff; + else if (datestr[15] == '+') + /* Represented time is ahead of UTC, shift it backward to UTC */ + *secs -= t_diff; - /* Subtract out the timezone information since we will adjust for - * the presented time's timezone below and then display in UTC. + /* Subtract out the timezone information since we adjusted for + * the presented time's timezone above and will display in UTC. * - * To do that, first determine the current timezone's offset to UTC. + * To do that, first determine how the time is represented in the + * local time zone and in UTC. */ - current_time = time(NULL); - gm = gmtime(¤t_time); + gm = gmtime(secs); gm_hour = gm->tm_hour; gm_min = gm->tm_min; - local_time = localtime(¤t_time); - /* Then subtract out that difference (whether the difference is - * measured in hours, minutes, or both). + local_time = localtime(secs); + + /* Then subtract out the difference between those times (whether the + * difference is measured in hours, minutes, or both). */ *secs -= 3600*(gm_hour - local_time->tm_hour); *secs -= 60*(gm_min - local_time->tm_min); - *nsecs = (datestr[12] - '0') * 100000000; - t_diff = (10 * (datestr[13] - '0') + (datestr[14] - '0')) * 900; - if (datestr[15] == '-') - /* Represented time is behind UTC, shift it forward to UTC */ - *secs += t_diff; - else if (datestr[15] == '+') - /* Represented time is ahead of UTC, shift it backward to UTC */ - *secs -= t_diff; } else { *secs = r_time.tm_sec + 60 * (r_time.tm_min + 60 * -- cgit v1.2.3