diff options
author | John David Anglin <danglin@gcc.gnu.org> | 2022-03-22 17:35:54 +0000 |
---|---|---|
committer | John David Anglin <danglin@gcc.gnu.org> | 2022-03-22 17:35:54 +0000 |
commit | 05dec22d7be722987ff07aebf9690f6078b3c4e9 (patch) | |
tree | 35a3443eabdceb4081450ac2869cd84dc5fcbc6b /resolv/resolv-internal.h | |
parent | bc0d18d873abf2cda6842ad8bb4df2a31dc0fbac (diff) | |
download | glibc-05dec22d7be722987ff07aebf9690f6078b3c4e9.zip glibc-05dec22d7be722987ff07aebf9690f6078b3c4e9.tar.gz glibc-05dec22d7be722987ff07aebf9690f6078b3c4e9.tar.bz2 |
resolv: Fix unaligned accesses to fields in HEADER struct
The structure HEADER is normally aligned to a word boundary but
sometimes it needs to be accessed when aligned on a byte boundary.
This change defines a new typedef, UHEADER, with alignment 1.
It is used to ensure the fields are accessed with byte loads and
stores when necessary.
V4: Change to res_mkquery.c deleted. Small whitespace fix.
V5: Move UHEADER typedef to resolv/resolv-internal.h. Replace all
HEADER usage with UHEADER in resolv/res_send.c.
Signed-off-by: John David Anglin <dave.anglin@bell.net>
Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Diffstat (limited to 'resolv/resolv-internal.h')
-rw-r--r-- | resolv/resolv-internal.h | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/resolv/resolv-internal.h b/resolv/resolv-internal.h index 2fa57d3..9d2e832 100644 --- a/resolv/resolv-internal.h +++ b/resolv/resolv-internal.h @@ -27,6 +27,13 @@ #define RES_F_CONN 0x00000002 /* Socket is connected. */ #define RES_F_EDNS0ERR 0x00000004 /* EDNS0 caused errors. */ +/* The structure HEADER is normally aligned on a word boundary. In + some code, we need to access this structure when it may be aligned + on a byte boundary. To avoid unaligned accesses, we need a typedef + with alignment one. This ensures the fields are accessed with byte + loads and stores. */ +typedef HEADER __attribute__ ((__aligned__(1))) UHEADER; + /* Legacy function. This needs to be removed once all NSS modules have been adjusted. */ static inline bool |