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/res_query.c | |
parent | bc0d18d873abf2cda6842ad8bb4df2a31dc0fbac (diff) | |
download | glibc-05dec22d7be722987ff07aebf9690f6078b3c4e9.tar.gz glibc-05dec22d7be722987ff07aebf9690f6078b3c4e9.tar.xz glibc-05dec22d7be722987ff07aebf9690f6078b3c4e9.zip |
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/res_query.c')
-rw-r--r-- | resolv/res_query.c | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/resolv/res_query.c b/resolv/res_query.c index 5d0a68dc81..3b5c604261 100644 --- a/resolv/res_query.c +++ b/resolv/res_query.c @@ -112,8 +112,8 @@ __res_context_query (struct resolv_context *ctx, const char *name, int *nanswerp2, int *resplen2, int *answerp2_malloced) { struct __res_state *statp = ctx->resp; - HEADER *hp = (HEADER *) answer; - HEADER *hp2; + UHEADER *hp = (UHEADER *) answer; + UHEADER *hp2; int n, use_malloc = 0; size_t bufsize = (type == T_QUERY_A_AND_AAAA ? 2 : 1) * QUERYSIZE; @@ -217,7 +217,7 @@ __res_context_query (struct resolv_context *ctx, const char *name, if (answerp != NULL) /* __res_context_send might have reallocated the buffer. */ - hp = (HEADER *) *answerp; + hp = (UHEADER *) *answerp; /* We simplify the following tests by assigning HP to HP2 or vice versa. It is easy to verify that this is the same as @@ -228,7 +228,7 @@ __res_context_query (struct resolv_context *ctx, const char *name, } else { - hp2 = (HEADER *) *answerp2; + hp2 = (UHEADER *) *answerp2; if (n < (int) sizeof (HEADER)) { hp = hp2; @@ -338,7 +338,7 @@ __res_context_search (struct resolv_context *ctx, { struct __res_state *statp = ctx->resp; const char *cp; - HEADER *hp = (HEADER *) answer; + UHEADER *hp = (UHEADER *) answer; char tmp[NS_MAXDNAME]; u_int dots; int trailing_dot, ret, saved_herrno; |