[Git][NTPsec/ntpsec][master] include/ntp.h: align V4/V6_SIZEOF_RESTRICT_U strides
Matt Selsky (@selsky)
gitlab at mg.gitlab.com
Fri Oct 9 22:49:56 UTC 2026
Matt Selsky pushed to branch master at NTPsec / ntpsec
Commits:
41aab4b3 by Matt Selsky at 2026-10-09T02:29:39-04:00
include/ntp.h: align V4/V6_SIZEOF_RESTRICT_U strides
The macros computed unaligned strides (28 and 52 bytes) for arrays of
restrict_u. The struct's alignment requirement (8 bytes on 64-bit platforms,
driven by the uint64_t hitcount field) was not preserved between consecutive
entries. On x86 this was silent UB; on strict-alignment platforms it would
SIGBUS. Round both sizes up to __alignof__(restrict_u) so the rounding adapts
if a stricter-aligned member is ever added.
Found with UBSan in test_ntpd.
- - - - -
1 changed file:
- include/ntp.h
Changes:
=====================================
include/ntp.h
=====================================
@@ -667,10 +667,14 @@ struct restrict_u_tag {
res_addr6 v6;
} u;
};
-#define V4_SIZEOF_RESTRICT_U (offsetof(restrict_u, u) \
- + sizeof(res_addr4))
-#define V6_SIZEOF_RESTRICT_U (offsetof(restrict_u, u) \
- + sizeof(res_addr6))
+/* Round up to preserve restrict_u alignment when these sizes are used as
+ * the stride between consecutive entries in an emalloc'd array. */
+#define V4_SIZEOF_RESTRICT_U ((offsetof(restrict_u, u) + sizeof(res_addr4) \
+ + __alignof__(restrict_u) - 1) \
+ & ~(__alignof__(restrict_u) - 1))
+#define V6_SIZEOF_RESTRICT_U ((offsetof(restrict_u, u) + sizeof(res_addr6) \
+ + __alignof__(restrict_u) - 1) \
+ & ~(__alignof__(restrict_u) - 1))
/* pythonize-header: stop ignoring */
View it on GitLab: https://gitlab.com/NTPsec/ntpsec/-/commit/41aab4b342457f76e700232f01e2d3a1b7bebbc5
--
View it on GitLab: https://gitlab.com/NTPsec/ntpsec/-/commit/41aab4b342457f76e700232f01e2d3a1b7bebbc5
You're receiving this email because of your account on gitlab.com. Manage all notifications: https://gitlab.com/-/profile/notifications | Help: https://gitlab.com/help
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ntpsec.org/pipermail/vc/attachments/20261009/7ea02c58/attachment-0001.htm>
More information about the vc
mailing list