submitted-resolv-unaligned
authorGNU Libc Maintainers <debian-glibc@lists.debian.org>
Sat, 16 Dec 2017 14:37:43 +0000 (14:37 +0000)
committerAurelien Jarno <aurel32@debian.org>
Sat, 16 Dec 2017 14:37:43 +0000 (14:37 +0000)
Gbp-Pq: Topic any
Gbp-Pq: Name submitted-resolv-unaligned.diff

resolv/res_mkquery.c
resolv/res_query.c
resolv/res_send.c

index 5a0bb1044b55a643b315294457a322cb9099dfb2..9a457e35ba0763f94957d1c43ee24916ad0f8fdb 100644 (file)
 # define RANDOM_BITS(Var) { uint64_t v64; HP_TIMING_NOW (v64); Var = v64; }
 #endif
 
+/* The structure HEADER is normally aligned to a word boundary and its
+   fields are accessed using word loads and stores.  We need to access
+   this structure when it is aligned on a byte boundary.  This can cause
+   problems on machines with strict alignment.  So, we create a new
+   typedef to reduce its alignment to one.  This ensures the fields are
+   accessed with byte loads and stores.  */
+typedef HEADER __attribute__ ((__aligned__(1))) UHEADER;
+#define HEADER UHEADER
+
 /*
  * Form all types of queries.
  * Returns the size of the result or -1.
index 57156d01ec3c9fc2169269ac53e1cd4bbb4f5e52..51e6b8b2ab4383fea6ddd082a0a266df9b6a3fad 100644 (file)
 /* Options.  Leave them on. */
 /* #undef DEBUG */
 
+/* The structure HEADER is normally aligned to a word boundary and its
+   fields are accessed using word loads and stores.  We need to access 
+   this structure when it is aligned on a byte boundary.  This can cause
+   problems on machines with strict alignment.  So, we create a new
+   typedef to reduce its alignment to one.  This ensures the fields are
+   accessed with byte loads and stores.  */
+typedef HEADER __attribute__ ((__aligned__(1))) UHEADER;
+
 #if PACKETSZ > 65536
 #define MAXPACKET      PACKETSZ
 #else
@@ -118,8 +126,8 @@ __libc_res_nquery(res_state statp,
                  int *resplen2,
                  int *answerp2_malloced)
 {
-       HEADER *hp = (HEADER *) answer;
-       HEADER *hp2;
+       UHEADER *hp = (UHEADER *) answer;
+       UHEADER *hp2;
        int n, use_malloc = 0;
        u_int oflags = statp->_flags;
 
@@ -250,7 +258,7 @@ __libc_res_nquery(res_state statp,
 
        if (answerp != NULL)
          /* __libc_res_nsend 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
@@ -261,7 +269,7 @@ __libc_res_nquery(res_state statp,
          }
        else
          {
-           hp2 = (HEADER *) *answerp2;
+           hp2 = (UHEADER *) *answerp2;
            if (n < (int) sizeof (HEADER))
              {
                hp = hp2;
@@ -351,7 +359,7 @@ __libc_res_nsearch(res_state statp,
                   int *answerp2_malloced)
 {
        const char *cp, * const *domain;
-       HEADER *hp = (HEADER *) answer;
+       UHEADER *hp = (UHEADER *) answer;
        char tmp[NS_MAXDNAME];
        u_int dots;
        int trailing_dot, ret, saved_herrno;
index 93db5b9a615ffde7111019df60e1a58db529f144..36a389509d9421aefde5b31863d397ac193bafb4 100644 (file)
 #include <kernel-features.h>
 #include <libc-internal.h>
 
+/* The structure HEADER is normally aligned to a word boundary and its
+   fields are accessed using word loads and stores.  We need to access 
+   this structure when it is aligned on a byte boundary.  This can cause
+   problems on machines with strict alignment.  So, we create a new
+   typedef to reduce its alignment to one.  This ensures the fields are
+   accessed with byte loads and stores.  */
+typedef HEADER __attribute__ ((__aligned__(1))) UHEADER;
+#define HEADER UHEADER
+
 #if PACKETSZ > 65536
 #define MAXPACKET       PACKETSZ
 #else