rwrap: Fix alignment issues on FreeBSD
authorAndreas Schneider <asn@samba.org>
Thu, 17 Oct 2019 15:49:47 +0000 (17:49 +0200)
committerAndreas Schneider <asn@cryptomilk.org>
Sun, 20 Oct 2019 12:59:27 +0000 (14:59 +0200)
Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
src/resolv_wrapper.c

index 10ab0cdf778773076237a5551c9f065e37e3c38a..5e9abc2749e4e8a7510ffa194373dde732c094e2 100644 (file)
@@ -397,29 +397,30 @@ static int rwrap_create_fake_ptr_rr(const char *key,
 static ssize_t rwrap_fake_header(uint8_t **header_blob, size_t remaining,
                                 size_t ancount, size_t arcount)
 {
-       uint8_t *hb;
-       HEADER *h;
+       union {
+               uint8_t *blob;
+               HEADER *header;
+       } h;
 
        if (remaining < NS_HFIXEDSZ) {
                RWRAP_LOG(RWRAP_LOG_ERROR, "Buffer too small!\n");
                return -1;
        }
 
-       hb = *header_blob;
-       memset(hb, 0, NS_HFIXEDSZ);
+       h.blob = *header_blob;
+       memset(h.blob, 0, NS_HFIXEDSZ);
 
-       h = (HEADER *) hb;
-       h->id = res_randomid();         /* random query ID */
-       h->qr = 1;                      /* response flag */
-       h->rd = 1;                      /* recursion desired */
-       h->ra = 1;                      /* recursion available */
+       h.header->id = res_randomid();          /* random query ID */
+       h.header->qr = 1;                       /* response flag */
+       h.header->rd = 1;                       /* recursion desired */
+       h.header->ra = 1;                       /* recursion available */
 
-       h->qdcount = htons(1);          /* no. of questions */
-       h->ancount = htons(ancount);    /* no. of answers */
-       h->arcount = htons(arcount);    /* no. of add'tl records */
+       h.header->qdcount = htons(1);           /* no. of questions */
+       h.header->ancount = htons(ancount);     /* no. of answers */
+       h.header->arcount = htons(arcount);     /* no. of add'tl records */
 
-       hb += NS_HFIXEDSZ;              /* move past the header */
-       *header_blob = hb;
+       /* move past the header */
+       *header_blob = h.blob += NS_HFIXEDSZ;
 
        return NS_HFIXEDSZ;
 }