Skip to content

Commit

Permalink
Fix unaligned access on successful lookups on interesting 64-bit syst…
Browse files Browse the repository at this point in the history
…ems (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
  • Loading branch information
kuroneko authored and lathiat committed Aug 9, 2016
1 parent 644e03c commit 837506f
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/nss.c
Expand Up @@ -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 {
Expand Down Expand Up @@ -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;
Expand All @@ -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++)
Expand Down

0 comments on commit 837506f

Please sign in to comment.