aboutsummaryrefslogtreecommitdiffstats
path: root/epan/dissectors/packet-ntp.c
diff options
context:
space:
mode:
authorJeff Morriss <jeff.morriss.ws@gmail.com>2012-10-25 22:26:52 +0000
committerJeff Morriss <jeff.morriss.ws@gmail.com>2012-10-25 22:26:52 +0000
commitd97b4ec325830bee235568138ba4151edc253c54 (patch)
tree837208043a832c28468bf2692f69433067ca30a6 /epan/dissectors/packet-ntp.c
parent4518ece9f954ab0e86a7c4e54c566919bb5cd1c1 (diff)
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/dissectors/packet-ntp.c')
-rw-r--r--epan/dissectors/packet-ntp.c19
1 files changed, 16 insertions, 3 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));
}