]> git.ipfire.org Git - thirdparty/chrony.git/commitdiff
ntp: add special value to experimental root delay/disp
authorMiroslav Lichvar <mlichvar@redhat.com>
Mon, 22 Nov 2021 10:39:29 +0000 (11:39 +0100)
committerMiroslav Lichvar <mlichvar@redhat.com>
Mon, 22 Nov 2021 14:21:29 +0000 (15:21 +0100)
The maximum value of the new 32-bit fields is slightly less than 16,
which can cause the NTP test #7 to pass for a server which has a zero
root delay but maximum root dispersion.

Interpret the maximum value as the maximum value of the original 32-bit
fields (~65536.0 seconds) for better compatibility with NTPv4.

test/unit/util.c
util.c

index 982a0ce8f5686937ef877220307b4fb4e18cf63a..4d7a4e8c7217b2a79bf893dc052f5d4ef411a3ff 100644 (file)
@@ -515,7 +515,9 @@ test_unit(void)
   TEST_CHECK(UTI_DoubleToNtp32f28(8.0) == htonl(0x80000000));
   TEST_CHECK(UTI_DoubleToNtp32f28(16.0) == htonl(0xffffffff));
   TEST_CHECK(UTI_DoubleToNtp32f28(16.1) == htonl(0xffffffff));
+  TEST_CHECK(UTI_DoubleToNtp32f28(16.1) == htonl(0xffffffff));
 
+  TEST_CHECK(UTI_Ntp32f28ToDouble(htonl(0xffffffff)) >= 65535.999);
   for (i = 0; i < 100000; i++) {
     UTI_GetRandomBytes(&ntp32_ts, sizeof (ntp32_ts));
     TEST_CHECK(UTI_DoubleToNtp32(UTI_Ntp32ToDouble(ntp32_ts)) == ntp32_ts);
diff --git a/util.c b/util.c
index 1f6648017e7c128de7caa5d88be21b7daf8f6c07..69f523d7a5bc5d4e2efcd5b25cbb8c3372dab03d 100644 (file)
--- a/util.c
+++ b/util.c
@@ -640,7 +640,13 @@ UTI_DoubleToNtp32(double x)
 double
 UTI_Ntp32f28ToDouble(NTP_int32 x)
 {
-  return ntohl(x) / (double)(1U << 28);
+  uint32_t r = ntohl(x);
+
+  /* Maximum value is special */
+  if (r == 0xffffffff)
+    return MAX_NTP_INT32;
+
+  return r / (double)(1U << 28);
 }
 
 /* ================================================== */