diff options
author | Jeff Morriss <jeff.morriss.ws@gmail.com> | 2012-10-25 22:26:52 +0000 |
---|---|---|
committer | Jeff Morriss <jeff.morriss.ws@gmail.com> | 2012-10-25 22:26:52 +0000 |
commit | d97b4ec325830bee235568138ba4151edc253c54 (patch) | |
tree | 837208043a832c28468bf2692f69433067ca30a6 /epan | |
parent | 4518ece9f954ab0e86a7c4e54c566919bb5cd1c1 (diff) | |
download | wireshark-d97b4ec325830bee235568138ba4151edc253c54.tar.gz |
Fix problem where NTP times with the high-bit set to 0 (which RFC 2030
chapter 3 has redefined to mean years *after* 2036) were being represented as
times prior to 1968.
This has been broken since r35840 (apparently not many people see NTP
timestamps beyond 2036 :-)): apparently I over-optimized packet-ntp's code
while copying it into proto.c: that temporary variable is necessary for the
unsigned math to happen correctly before assigning the result to the (signed)
time_t.
Leave a comment in the code indicating why the temporary variable is needed.
Copy that comment to packet-ntp.c.
Fix the same problem in ntp_to_nstime(): it also did not use the temporary variable.
svn path=/trunk/; revision=45790
Diffstat (limited to 'epan')
-rw-r--r-- | epan/dissectors/packet-ntp.c | 19 | ||||
-rw-r--r-- | epan/proto.c | 24 |
2 files changed, 33 insertions, 10 deletions
diff --git a/epan/dissectors/packet-ntp.c b/epan/dissectors/packet-ntp.c index 5d113c7eb1..e32a2693fa 100644 --- a/epan/dissectors/packet-ntp.c +++ b/epan/dissectors/packet-ntp.c @@ -644,6 +644,10 @@ tvb_ntp_fmt_ts(tvbuff_t *tvb, gint offset) return "NULL"; } + /* We need a temporary variable here so the unsigned math + * works correctly (for years > 2036 according to RFC 2030 + * chapter 3). + */ temptime = tempstmp - (guint32) NTP_BASETIME; bd = gmtime(&temptime); if(!bd){ @@ -666,9 +670,18 @@ tvb_ntp_fmt_ts(tvbuff_t *tvb, gint offset) void ntp_to_nstime(tvbuff_t *tvb, gint offset, nstime_t *nstime) { - nstime->secs = tvb_get_ntohl(tvb, offset); - if (nstime->secs) - nstime->secs -= NTP_BASETIME; + guint32 tempstmp; + + /* We need a temporary variable here so the unsigned math + * works correctly (for years > 2036 according to RFC 2030 + * chapter 3). + */ + tempstmp = tvb_get_ntohl(tvb, offset); + if (tempstmp) + nstime->secs = tempstmp - (guint32)NTP_BASETIME; + else + nstime->secs = tempstmp; /* 0 */ + nstime->nsecs = (int)(tvb_get_ntohl(tvb, offset+4)/(NTP_FLOAT_DENOM/1000000000.0)); } diff --git a/epan/proto.c b/epan/proto.c index 3d47074ab7..c08d46eb31 100644 --- a/epan/proto.c +++ b/epan/proto.c @@ -618,7 +618,7 @@ void proto_tree_reset(proto_tree *tree) { tree_data_t *tree_data = PTREE_DATA(tree); - + proto_tree_children_foreach(tree, proto_tree_free_node, NULL); /* reset tree */ @@ -1230,6 +1230,7 @@ proto_tree_new_item(field_info *new_fi, proto_tree *tree, double doubleval; const char *string; nstime_t time_stamp; + guint32 tmpsecs; GPtrArray *ptrs; gboolean length_error; @@ -1626,9 +1627,16 @@ proto_tree_new_item(field_info *new_fi, proto_tree *tree, /* XXX - where should this go? */ #define NTP_BASETIME 2208988800ul - time_stamp.secs = tvb_get_ntohl(tvb, start); - if (time_stamp.secs) - time_stamp.secs -= NTP_BASETIME; + + /* We need a temporary variable here so the unsigned math + * works correctly (for years > 2036 according to RFC 2030 + * chapter 3). + */ + tmpsecs = tvb_get_ntohl(tvb, start); + if (tmpsecs) + time_stamp.secs = tmpsecs - (guint32)NTP_BASETIME; + else + time_stamp.secs = tmpsecs; /* 0 */ if (length == 8) { /* @@ -1648,9 +1656,11 @@ proto_tree_new_item(field_info *new_fi, proto_tree *tree, /* * NTP time stamp, big-endian. */ - time_stamp.secs = tvb_get_letohl(tvb, start); - if (time_stamp.secs) - time_stamp.secs -= NTP_BASETIME; + tmpsecs = tvb_get_letohl(tvb, start); + if (tmpsecs) + time_stamp.secs = tmpsecs - (guint32)NTP_BASETIME; + else + time_stamp.secs = tmpsecs; /* 0 */ if (length == 8) { /* |