about summary refs log tree commit diff
path: root/src/network
diff options
context:
space:
mode:
authorRich Felker <dalias@aerifal.cx>2016-06-27 17:11:30 -0400
committerRich Felker <dalias@aerifal.cx>2016-06-27 17:11:30 -0400
commit4da0bc5ef8e0fdea65335599d947d74b7b321daa (patch)
tree73c4f83cbf63b449eebe4fa56d84118773e5fc5d /src/network
parent384d103d94dba0472a587861f67d7ed6e8955f86 (diff)
downloadmusl-4da0bc5ef8e0fdea65335599d947d74b7b321daa.tar.gz
musl-4da0bc5ef8e0fdea65335599d947d74b7b321daa.tar.xz
musl-4da0bc5ef8e0fdea65335599d947d74b7b321daa.zip
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.
Diffstat (limited to 'src/network')
-rw-r--r--src/network/gethostbyname2_r.c14
1 files changed, 7 insertions, 7 deletions
diff --git a/src/network/gethostbyname2_r.c b/src/network/gethostbyname2_r.c
index 81f71d21..5c1cae98 100644
--- a/src/network/gethostbyname2_r.c
+++ b/src/network/gethostbyname2_r.c
@@ -58,6 +58,13 @@ int gethostbyname2_r(const char *name, int af,
 	h->h_addr_list = (void *)buf;
 	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;
 	strcpy(h->h_name, canon);
 	buf += strlen(h->h_name)+1;
@@ -70,13 +77,6 @@ int gethostbyname2_r(const char *name, int af,
 
 	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;
 	return 0;
 }