[Git][NTPsec/ntpsec][master] ntp_control.h: Fix excessive alignment requirement.

Hal Murray (@hal.murray) gitlab at mg.gitlab.com
Mon Feb 17 06:57:13 UTC 2025



Hal Murray pushed to branch master at NTPsec / ntpsec


Commits:
9bdb54e9 by Fred Wright at 2025-02-16T19:45:25-08:00
ntp_control.h: Fix excessive alignment requirement.

According to both the comment and the referenced issue, the
requirement is to be aligned to a 32-*bit* boundary, but the argument
to the __attribute__((aligned())) is in *bytes*.  The correct
alignment value should thus be 4, not 32.

This caused a warning on OpenBSD 5.6, where the compiler was unable to
guarantee 32-byte alignment of stack variables.

Also fixes the misleading comment.  The issue isn't specifically about
32-bit platforms.

NOTE: Removing the alignment altogether doesn't currently cause the
build to fail on a Beaglebone here (Debian 7, gcc 4.6.3), so there
isn't solid proof that this addresses issue #277, but the updated
alignment matches the stated intent of the original fix.

TESTED:
Built and ran tests on OSX 10.4-10.5 ppc, 10.4-10.6 i386, 10.5-12.x
x86_64, 11.x-15.x arm64, Debian 7 arm, Debian 10 arm64, Ubuntu 14
x86_64, CentOS 7 x86_64, Fedora 25 x86_64, Ubuntu 22 x86_64, FreeBSD
10.3 x86_64, OpenBSD 5.6 x86_64, and OpenBSD i386.

- - - - -


1 changed file:

- include/ntp_control.h


Changes:

=====================================
include/ntp_control.h
=====================================
@@ -12,11 +12,11 @@
 #include "ntp_types.h"
 
 /* The attribute after this structure is a gcc/clang extension that forces
- * the beginning of a structure instance to be 32-bit aligned.  Without this
- * attempting to compile on a 32-bit host may throw warnings or errors when
- * a pointer to this structure is passed to authdecrypt/authencrypt, both of
- * which expect to be able to treat the structure as an array of uint32_t
- * elements.  Ideally, we'd get rid of that nasty type punning. */
+ * the beginning of a structure instance to be 32-bit aligned.  Without this,
+ * attempting to compile on an alignment-sensitive host may throw warnings or
+ * errors when a pointer to this structure is passed to authdecrypt/authencrypt,
+ * both of which expect to be able to treat the structure as an array of
+ * uint32_t elements.  Ideally, we'd get rid of that nasty type punning. */
 struct ntp_control {
 	uint8_t li_vn_mode;		/* leap, version, mode */
 	uint8_t r_m_e_op;		/* response, more, error, opcode */
@@ -27,7 +27,7 @@ struct ntp_control {
         /* the draft RFC says 0 <= count <= 468 */
 	uint16_t count;			/* byte count of data in this packet */
 	uint8_t data[480 + MAX_MAC_LEN]; /* data + padding + auth */
-} __attribute__((aligned(32)));
+} __attribute__((aligned(4)));
 
 /*
  * Length of the control header, in octets



View it on GitLab: https://gitlab.com/NTPsec/ntpsec/-/commit/9bdb54e983d380e8473b4f7099e5e173f03c73ee

-- 
View it on GitLab: https://gitlab.com/NTPsec/ntpsec/-/commit/9bdb54e983d380e8473b4f7099e5e173f03c73ee
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/20250217/fb3dd147/attachment-0001.htm>


More information about the vc mailing list