aboutsummaryrefslogtreecommitdiff
path: root/resolv/res_send.c
diff options
context:
space:
mode:
authorJohn David Anglin <danglin@gcc.gnu.org>2022-03-22 17:35:54 +0000
committerJohn David Anglin <danglin@gcc.gnu.org>2022-03-22 17:35:54 +0000
commit05dec22d7be722987ff07aebf9690f6078b3c4e9 (patch)
tree35a3443eabdceb4081450ac2869cd84dc5fcbc6b /resolv/res_send.c
parentbc0d18d873abf2cda6842ad8bb4df2a31dc0fbac (diff)
downloadglibc-05dec22d7be722987ff07aebf9690f6078b3c4e9.tar
glibc-05dec22d7be722987ff07aebf9690f6078b3c4e9.tar.gz
glibc-05dec22d7be722987ff07aebf9690f6078b3c4e9.tar.bz2
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_send.c')
-rw-r--r--resolv/res_send.c18
1 files changed, 9 insertions, 9 deletions
diff --git a/resolv/res_send.c b/resolv/res_send.c
index 5d6be4b82d..d6c85fd7a2 100644
--- a/resolv/res_send.c
+++ b/resolv/res_send.c
@@ -245,7 +245,7 @@ static void
mask_ad_bit (struct resolv_context *ctx, void *buf)
{
if (!(ctx->resp->options & RES_TRUSTAD))
- ((HEADER *) buf)->ad = 0;
+ ((UHEADER *) buf)->ad = 0;
}
int
@@ -560,9 +560,9 @@ send_vc(res_state statp,
int *terrno, int ns, u_char **anscp, u_char **ansp2, int *anssizp2,
int *resplen2, int *ansp2_malloced)
{
- const HEADER *hp = (HEADER *) buf;
- const HEADER *hp2 = (HEADER *) buf2;
- HEADER *anhp = (HEADER *) *ansp;
+ const UHEADER *hp = (UHEADER *) buf;
+ const UHEADER *hp2 = (UHEADER *) buf2;
+ UHEADER *anhp = (UHEADER *) *ansp;
struct sockaddr *nsap = __res_get_nsaddr (statp, ns);
int truncating, connreset, n;
/* On some architectures compiler might emit a warning indicating
@@ -697,7 +697,7 @@ send_vc(res_state statp,
thisansp = ansp2;
thisresplenp = resplen2;
}
- anhp = (HEADER *) *thisansp;
+ anhp = (UHEADER *) *thisansp;
*thisresplenp = rlen;
/* Is the answer buffer too small? */
@@ -718,7 +718,7 @@ send_vc(res_state statp,
*thisansp = newp;
if (thisansp == ansp2)
*ansp2_malloced = 1;
- anhp = (HEADER *) newp;
+ anhp = (UHEADER *) newp;
/* A uint16_t can't be larger than MAXPACKET
thus it's safe to allocate MAXPACKET but
read RLEN bytes instead. */
@@ -925,8 +925,8 @@ send_dg(res_state statp,
int *terrno, int ns, int *v_circuit, int *gotsomewhere, u_char **anscp,
u_char **ansp2, int *anssizp2, int *resplen2, int *ansp2_malloced)
{
- const HEADER *hp = (HEADER *) buf;
- const HEADER *hp2 = (HEADER *) buf2;
+ const UHEADER *hp = (UHEADER *) buf;
+ const UHEADER *hp2 = (UHEADER *) buf2;
struct timespec now, timeout, finish;
struct pollfd pfd[1];
int ptimeout;
@@ -1168,7 +1168,7 @@ send_dg(res_state statp,
MSG_TRUNC which is only available on Linux. We
can abstract out the Linux-specific feature in the
future to detect truncation. */
- HEADER *anhp = (HEADER *) *thisansp;
+ UHEADER *anhp = (UHEADER *) *thisansp;
socklen_t fromlen = sizeof(struct sockaddr_in6);
assert (sizeof(from) <= fromlen);
*thisresplenp = __recvfrom (pfd[0].fd, (char *) *thisansp,