mirror of git://git.musl-libc.org/musl
fix misaligned address buffers in gethostbyname[2][_r] results
mistakenly ordering strings before addresses in the result buffer broke the alignment that the preceding code had set up.
This commit is contained in:
parent
384d103d94
commit
4da0bc5ef8
|
@ -58,6 +58,13 @@ int gethostbyname2_r(const char *name, int af,
|
||||||
h->h_addr_list = (void *)buf;
|
h->h_addr_list = (void *)buf;
|
||||||
buf += (cnt+1)*sizeof(char *);
|
buf += (cnt+1)*sizeof(char *);
|
||||||
|
|
||||||
|
for (i=0; i<cnt; i++) {
|
||||||
|
h->h_addr_list[i] = (void *)buf;
|
||||||
|
buf += h->h_length;
|
||||||
|
memcpy(h->h_addr_list[i], addrs[i].addr, h->h_length);
|
||||||
|
}
|
||||||
|
h->h_addr_list[i] = 0;
|
||||||
|
|
||||||
h->h_name = h->h_aliases[0] = buf;
|
h->h_name = h->h_aliases[0] = buf;
|
||||||
strcpy(h->h_name, canon);
|
strcpy(h->h_name, canon);
|
||||||
buf += strlen(h->h_name)+1;
|
buf += strlen(h->h_name)+1;
|
||||||
|
@ -70,13 +77,6 @@ int gethostbyname2_r(const char *name, int af,
|
||||||
|
|
||||||
h->h_aliases[2] = 0;
|
h->h_aliases[2] = 0;
|
||||||
|
|
||||||
for (i=0; i<cnt; i++) {
|
|
||||||
h->h_addr_list[i] = (void *)buf;
|
|
||||||
buf += h->h_length;
|
|
||||||
memcpy(h->h_addr_list[i], addrs[i].addr, h->h_length);
|
|
||||||
}
|
|
||||||
h->h_addr_list[i] = 0;
|
|
||||||
|
|
||||||
*res = h;
|
*res = h;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue