1
0
mirror of https://sourceware.org/git/glibc.git synced 2025-07-29 11:41:21 +03:00

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>
This commit is contained in:
John David Anglin
2022-03-22 17:35:54 +00:00
parent bc0d18d873
commit 05dec22d7b
3 changed files with 21 additions and 14 deletions

View File

@ -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