aboutsummaryrefslogtreecommitdiffstats
path: root/main/ncftp/remove-alloca-use.patch
blob: 0ed63e436fb33b493c50ddc0396861d7caec4cf7 (plain)
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
The alloca() use in sio is incorrect. gethostby*_r will make the hostent
contain pointers to the submitted area, but when the function returns the
alloca() allocated area is freed. Always use the supplied buffer.

diff -ru ncftp-3.2.5.orig/sio/DNSUtil.c ncftp-3.2.5/sio/DNSUtil.c
--- ncftp-3.2.5.orig/sio/DNSUtil.c	2009-10-24 02:31:23.000000000 +0300
+++ ncftp-3.2.5/sio/DNSUtil.c	2016-03-22 16:17:36.809816988 +0200
@@ -50,6 +50,13 @@
 			errno = ENOENT;
 		break;
 	}
+#elif defined(HAVE_GETHOSTBYNAME_R) && defined(LINUX)
+	struct hostent *h;
+	int h_errno_unused = 0, r;
+	memset(hpbuf, 0, hpbufsize);
+	r = gethostbyname_r(name, hp, hpbuf, hpbufsize, &h, &h_errno_unused);
+	if (r == 0 && h != NULL)
+		return (0);
 #elif defined(HAVE_GETHOSTBYNAME_R) && (defined(SOLARIS) || defined(IRIX) || defined(BSDOS))
 	struct hostent *h;
 	int h_errno_unused = 0;
@@ -57,60 +64,6 @@
 	h = gethostbyname_r(name, hp, hpbuf, hpbufsize, &h_errno_unused);
 	if (h != NULL)
 		return (0);
-#elif defined(HAVE_GETHOSTBYNAME2_R) && defined(LINUX) && defined(HAVE_ALLOCA)
-	char *usehpbuf;
-	struct hostent *h;
-	int my_h_errno, rc;
-
-	usehpbuf = hpbuf;
-	forever {
-		errno = 0;
-		my_h_errno = 0;
-		h = NULL;
-		memset(usehpbuf, 0, hpbufsize);
-		rc = gethostbyname2_r(name, AF_INET, hp, usehpbuf, hpbufsize, &h, &my_h_errno);
-		if ((rc == 0) && (h != NULL))
-			return (0);
-		if ((rc == ERANGE) || ((rc == -1) && (errno == ERANGE))) {
-			hpbufsize *= 2;
-			usehpbuf = alloca(hpbufsize);
-			if (usehpbuf == NULL) {
-				errno = ENOMEM;
-				return (-1);
-			}
-			continue;
-		}
-		if ((rc == 0) && (my_h_errno != 0))
-			errno = ENOENT;
-		break;
-	}
-#elif defined(HAVE_GETHOSTBYNAME_R) && defined(LINUX) && defined(HAVE_ALLOCA)
-	char *usehpbuf;
-	struct hostent *h;
-	int my_h_errno, rc;
-
-	usehpbuf = hpbuf;
-	forever {
-		errno = 0;
-		my_h_errno = 0;
-		h = NULL;
-		memset(usehpbuf, 0, hpbufsize);
-		rc = gethostbyname_r(name, hp, usehpbuf, hpbufsize, &h, &my_h_errno);
-		if ((rc == 0) && (h != NULL))
-			return (0);
-		if ((rc == ERANGE) || ((rc == -1) && (errno == ERANGE))) {
-			hpbufsize *= 2;
-			usehpbuf = alloca(hpbufsize);
-			if (usehpbuf == NULL) {
-				errno = ENOMEM;
-				return (-1);
-			}
-			continue;
-		}
-		if ((rc == 0) && (my_h_errno != 0))
-			errno = ENOENT;
-		break;
-	}
 #elif defined(HAVE_GETHOSTBYNAME_R) && defined(AIX)
 	struct hostent_data hed;
 	memset(hpbuf, 0, hpbufsize);
@@ -152,6 +105,13 @@
 			return (-2);
 		return (0);
 	}
+#elif defined(HAVE_GETHOSTBYADDR_R) && defined(LINUX)
+	struct hostent *h;
+	int h_errno_unused = 0, r;
+	memset(hpbuf, 0, hpbufsize);
+	r = gethostbyaddr_r((const void *) addr, asize, atype, hp, hpbuf, hpbufsize, &h, &h_errno_unused);
+	if (r == 0 && h != NULL)
+		return (0);
 #elif defined(HAVE_GETHOSTBYADDR_R) && (defined(SOLARIS) || defined(IRIX) || defined(BSDOS))
 	struct hostent *h;
 	int h_errno_unused = 0;
@@ -159,33 +119,6 @@
 	h = gethostbyaddr_r((gethost_addrptr_t) addr, asize, atype, hp, hpbuf, hpbufsize, &h_errno_unused);
 	if (h != NULL)
 		return (0);
-#elif defined(HAVE_GETHOSTBYADDR_R) && defined(LINUX) && defined(HAVE_ALLOCA)
-	char *usehpbuf;
-	struct hostent *h;
-	int my_h_errno, rc;
-
-	usehpbuf = hpbuf;
-	forever {
-		errno = 0;
-		my_h_errno = 0;
-		h = NULL;
-		memset(usehpbuf, 0, hpbufsize);
-		rc = gethostbyaddr_r((gethost_addrptr_t) addr, asize, atype, hp, usehpbuf, hpbufsize, &h, &my_h_errno);
-		if ((rc == 0) && (h != NULL))
-			return (0);
-		if ((rc == ERANGE) || ((rc == -1) && (errno == ERANGE))) {
-			hpbufsize *= 2;
-			usehpbuf = alloca(hpbufsize);
-			if (usehpbuf == NULL) {
-				errno = ENOMEM;
-				return (-1);
-			}
-			continue;
-		}
-		if ((rc == 0) && (my_h_errno != 0))
-			errno = ENOENT;
-		break;
-	}
 #elif defined(HAVE_GETHOSTBYADDR_R) && defined(AIX)
 	struct hostent_data hed;
 	memset(hpbuf, 0, hpbufsize);