]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
nss_dns: Check for proper A/AAAA address alignment
authorFlorian Weimer <fweimer@redhat.com>
Fri, 24 May 2019 20:14:04 +0000 (22:14 +0200)
committerFlorian Weimer <fweimer@redhat.com>
Fri, 24 May 2019 20:14:04 +0000 (22:14 +0200)
Reviewed-by: Carlos O'Donell <carlos@redhat.com>
ChangeLog
resolv/nss_dns/dns-host.c

index 5f21fe463a914a24f71468c746dbb8fac87d1780..b46b581707b7ffa4ffe711bcd321f83e7007521b 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2019-05-24  Florian Weimer  <fweimer@redhat.com>
+
+       * resolv/nss_dns/dns-host.c (getanswer_r): Be more explicit about
+       struct in_addr/struct in6_addr alignment.
+
 2019-05-23  Joseph Myers  <joseph@codesourcery.com>
 
        * sysdeps/unix/sysv/linux/bits/fcntl-linux.h [__USE_GNU]
index 9c15f25f283ffd881dc209993c40085f7ec31cbb..5af47fd10dcd164d33386198c17cfceec06fbc80 100644 (file)
@@ -78,6 +78,7 @@
 #include <stdlib.h>
 #include <stddef.h>
 #include <string.h>
+#include <libc-pointer-arith.h>
 
 #include "nsswitch.h"
 #include <arpa/nameser.h>
@@ -947,8 +948,18 @@ getanswer_r (struct resolv_context *ctx,
              linebuflen -= nn;
            }
 
-         linebuflen -= sizeof (align) - ((u_long) bp % sizeof (align));
-         bp += sizeof (align) - ((u_long) bp % sizeof (align));
+         /* Provide sufficient alignment for both address
+            families.  */
+         enum { align = 4 };
+         _Static_assert ((align % __alignof__ (struct in_addr)) == 0,
+                         "struct in_addr alignment");
+         _Static_assert ((align % __alignof__ (struct in6_addr)) == 0,
+                         "struct in6_addr alignment");
+         {
+           char *new_bp = PTR_ALIGN_UP (bp, align);
+           linebuflen -= new_bp - bp;
+           bp = new_bp;
+         }
 
          if (__glibc_unlikely (n > linebuflen))
            goto too_small;