[Git][NTPsec/ntpsec][master] 3 commits: On 32-bit systems, number of seconds in a GPS epoch may overflow

Eric S. Raymond gitlab at mg.gitlab.com
Sat Aug 17 04:12:21 UTC 2019



Eric S. Raymond pushed to branch master at NTPsec / ntpsec


Commits:
f45fdcd2 by Sanjeev Gupta at 2019-08-16T21:18:37Z
On 32-bit systems, number of seconds in a GPS epoch may overflow

On a gcc 8.3 on a 32-bit system,
Size of int: 4 bytes
Size of long int: 4 bytes
Size of long long int: 8 bytes
Size of float: 4 bytes
Size of double: 8 bytes
Size of long double: 12 bytes
Size of char: 1 byte

Explicitly cast to (long double) to prevent overflow of the
seconds in a 13-bit week number

- - - - -
1c850f70 by Sanjeev Gupta at 2019-08-16T21:32:22Z
Slightly cleaner cast to long double

- - - - -
774dc083 by Sanjeev Gupta at 2019-08-16T22:22:01Z
Switch from float to integer

Gary pointed out the dangers of using a float to store this
value.

So (long double) is out.

(long long) is 8 bytes, but we can only use 4, because it
is signed.

Use (unsigned long long), which gives us the full 8 bytes.

- - - - -


1 changed file:

- ntpd/ntp_scanner.c


Changes:

=====================================
ntpd/ntp_scanner.c
=====================================
@@ -35,7 +35,7 @@
 #include "ntp_keyword.h"
 
 /* used to implement g and G suffixes for numeric literals in fudge offset declarations */
-#define SECONDS_IN_WEEK	(7L * 24L * 60L * 60L)
+#define SECONDS_IN_WEEK	(unsigned long long)(7 * 24 * 60 * 60) /* 32bit systems*/
 #define GPS_ERA_10BIT	(1024L * SECONDS_IN_WEEK)
 #define GPS_ERA_13BIT	(8192L * SECONDS_IN_WEEK)
 #define ERA_SUFFIX(c)	((c) == 'g' || (c) == 'G')



View it on GitLab: https://gitlab.com/NTPsec/ntpsec/compare/f99a5882101c4c3463ca6f057790cded22f21c70...774dc083044faa2a7ecce1eb660386d7dba8c2f8

-- 
View it on GitLab: https://gitlab.com/NTPsec/ntpsec/compare/f99a5882101c4c3463ca6f057790cded22f21c70...774dc083044faa2a7ecce1eb660386d7dba8c2f8
You're receiving this email because of your account on gitlab.com.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ntpsec.org/pipermail/vc/attachments/20190817/bd64de35/attachment.htm>


More information about the vc mailing list