diff options
author | Florian Weimer <fweimer@redhat.com> | 2019-05-24 22:14:04 +0200 |
---|---|---|
committer | Florian Weimer <fweimer@redhat.com> | 2019-05-24 22:14:04 +0200 |
commit | 5c23c82195fc9e95ae34180250f64438f1e6fb0b (patch) | |
tree | 3f0d15867781144e230a9aa8cb3f69277fc18493 /resolv | |
parent | bee1f2c413ef0cf99d25f898fa0eb0d41fb71dc5 (diff) | |
download | glibc-5c23c82195fc9e95ae34180250f64438f1e6fb0b.tar.gz glibc-5c23c82195fc9e95ae34180250f64438f1e6fb0b.tar.xz glibc-5c23c82195fc9e95ae34180250f64438f1e6fb0b.zip |
nss_dns: Check for proper A/AAAA address alignment
Reviewed-by: Carlos O'Donell <carlos@redhat.com>
Diffstat (limited to 'resolv')
-rw-r--r-- | resolv/nss_dns/dns-host.c | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/resolv/nss_dns/dns-host.c b/resolv/nss_dns/dns-host.c index 9c15f25f28..5af47fd10d 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; |