1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
From 4da0bc5ef8e0fdea65335599d947d74b7b321daa Mon Sep 17 00:00:00 2001
From: Rich Felker <dalias@aerifal.cx>
Date: Mon, 27 Jun 2016 17:11:30 -0400
Subject: [PATCH] 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.
---
src/network/gethostbyname2_r.c | 14 +++++++-------
1 file changed, 7 insertions(+), 7 deletions(-)
diff --git a/src/network/gethostbyname2_r.c b/src/network/gethostbyname2_r.c
index 81f71d2..5c1cae9 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;
}
--
2.9.1
|