This is the mail archive of the
glibc-cvs@sourceware.org
mailing list for the glibc project.
[glibc] nss_dns: Check for proper A/AAAA address alignment
- From: Florian Weimer <fw at sourceware dot org>
- To: glibc-cvs at sourceware dot org
- Date: 24 May 2019 20:14:41 -0000
- Subject: [glibc] nss_dns: Check for proper A/AAAA address alignment
https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=5c23c82195fc9e95ae34180250f64438f1e6fb0b
commit 5c23c82195fc9e95ae34180250f64438f1e6fb0b
Author: Florian Weimer <fweimer@redhat.com>
Date: Fri May 24 22:14:04 2019 +0200
nss_dns: Check for proper A/AAAA address alignment
Reviewed-by: Carlos O'Donell <carlos@redhat.com>
Diff:
---
ChangeLog | 5 +++++
resolv/nss_dns/dns-host.c | 15 +++++++++++++--
2 files changed, 18 insertions(+), 2 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 5f21fe4..b46b581 100644
--- 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]
diff --git a/resolv/nss_dns/dns-host.c b/resolv/nss_dns/dns-host.c
index 9c15f25..5af47fd 100644
--- a/resolv/nss_dns/dns-host.c
+++ b/resolv/nss_dns/dns-host.c
@@ -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;