submitted-resolv-unaligned
authorGNU Libc Maintainers <debian-glibc@lists.debian.org>
Sat, 27 Aug 2022 11:38:11 +0000 (12:38 +0100)
committerAurelien Jarno <aurel32@debian.org>
Sat, 27 Aug 2022 11:38:11 +0000 (12:38 +0100)
Gbp-Pq: Topic any
Gbp-Pq: Name submitted-resolv-unaligned.diff

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

index ba6c983b58c4e625f26f4f371fcc62093a302244..434a0c6dcdd8ff84cae65d56a8e6dbef0d6c145b 100644 (file)
 #include <shlib-compat.h>
 #include <random-bits.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
+
 int
 __res_context_mkquery (struct resolv_context *ctx, int op, const char *dname,
                        int class, int type, const unsigned char *data,
index 75b0e5f2f7b51eb2c2c3ce4c12102651a9832ab1..f09d1f608f1b3e37a41aeff6965c279a30b2a3c4 100644 (file)
 #include <string.h>
 #include <shlib-compat.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;
+
 #if PACKETSZ > 65536
 #define MAXPACKET      PACKETSZ
 #else
@@ -112,8 +120,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 +225,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 +236,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 +346,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;
index 9f86f5fe471948878098af41ea38174d9a6d4744..0fb6e2392e4edb3ab2fb03b56bbe6e30db07c563 100644 (file)
 #include <libc-diag.h>
 #include <random-bits.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