From 837506f5df4f0d109abd73cd7e06fe3b9c570050 Mon Sep 17 00:00:00 2001 From: Chris Collins Date: Tue, 9 Aug 2016 15:21:34 +0100 Subject: [PATCH] Fix unaligned access on successful lookups on interesting 64-bit systems (ia64) This is due to poor alignment of results in the result buffer Patch imported from Debian: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=521184 --- src/nss.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/nss.c b/src/nss.c index 13c8109..e6881dc 100644 --- a/src/nss.c +++ b/src/nss.c @@ -69,7 +69,7 @@ #define ALIGN(idx) do { \ if (idx % sizeof(void*)) \ - idx += (sizeof(void*) - idx % sizeof(void*)); /* Align on 32 bit boundary */ \ + idx += (sizeof(void*) - idx % sizeof(void*)); /* Align on word boundary */ \ } while(0) struct userdata { @@ -514,7 +514,7 @@ enum nss_status _nss_mdns_gethostbyname2_r( result->h_length = address_length; /* Check if there's enough space for the addresses */ - if (buflen < idx+u.data_len+sizeof(char*)*(u.count+1)) { + if (buflen < idx+u.data_len+sizeof(char*)*(u.count+1)+sizeof(void*)) { *errnop = ERANGE; *h_errnop = NO_RECOVERY; status = NSS_STATUS_TRYAGAIN; @@ -525,9 +525,10 @@ enum nss_status _nss_mdns_gethostbyname2_r( astart = idx; l = u.count*address_length; memcpy(buffer+astart, &u.data, l); - /* address_length is a multiple of 32bits, so idx is still aligned - * correctly */ idx += l; + /* realign, whilst the address is a multiple of 32bits, we + * frequently lose alignment for 64bit systems */ + ALIGN(idx); /* Address array address_lenght is always a multiple of 32bits */ for (i = 0; i < u.count; i++)