aboutsummaryrefslogtreecommitdiffstats
path: root/main/lua-cqueues/dns-fix.patch
blob: 1ad02df77402df1ee8d7848eaceca9d63d5d7747 (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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
From e1677a4dc4737f5dce7faaa535ce52f2381bbd20 Mon Sep 17 00:00:00 2001
From: daurnimator <quae@daurnimator.com>
Date: Sat, 16 Jun 2018 20:35:39 +0100
Subject: [PATCH] src/lib/dns.c: Bring in fixes from
 https://github.com/wahern/dns/pull/27

---
 src/lib/dns.c | 78 ++++++++++++++++++++++++++++++++++++++++++---------
 1 file changed, 64 insertions(+), 14 deletions(-)

diff --git a/src/lib/dns.c b/src/lib/dns.c
index a6bb6a6..23a350b 100644
--- a/src/lib/dns.c
+++ b/src/lib/dns.c
@@ -28,6 +28,9 @@
 #define _XOPEN_SOURCE	600
 #endif
 
+#undef _DEFAULT_SOURCE
+#define _DEFAULT_SOURCE
+
 #undef _BSD_SOURCE
 #define _BSD_SOURCE
 
@@ -203,10 +206,11 @@
 #endif
 
 #ifndef HAVE_STATIC_ASSERT
-#if DNS_GNUC_PREREQ(0,0,0) && !DNS_GNUC_PREREQ(4,6,0)
-#define HAVE_STATIC_ASSERT 0 /* glibc doesn't check GCC version */
+#if (defined static_assert) && \
+	(!DNS_GNUC_PREREQ(0,0,0) || DNS_GNUC_PREREQ(4,6,0)) /* glibc doesn't check GCC version */
+#define HAVE_STATIC_ASSERT 1
 #else
-#define HAVE_STATIC_ASSERT (defined static_assert)
+#define HAVE_STATIC_ASSERT 0
 #endif
 #endif
 
@@ -372,7 +376,11 @@ const char *dns_strerror(int error) {
  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
 
 #ifndef HAVE___ATOMIC_FETCH_ADD
-#define HAVE___ATOMIC_FETCH_ADD (defined __ATOMIC_RELAXED)
+#ifdef __ATOMIC_RELAXED
+#define HAVE___ATOMIC_FETCH_ADD 1
+#else
+#define HAVE___ATOMIC_FETCH_ADD 0
+#endif
 #endif
 
 #ifndef HAVE___ATOMIC_FETCH_SUB
@@ -779,7 +787,11 @@ DNS_NOTUSED static size_t dns_strnlcpy(char *dst, size_t lim, const char *src, s
 } /* dns_strnlcpy() */
 
 
-#define DNS_HAVE_SOCKADDR_UN (defined AF_UNIX && !defined _WIN32)
+#if (defined AF_UNIX && !defined _WIN32)
+#define DNS_HAVE_SOCKADDR_UN 1
+#else
+#define DNS_HAVE_SOCKADDR_UN 0
+#endif
 
 static size_t dns_af_len(int af) {
 	static const size_t table[AF_MAX]	= {
@@ -4419,6 +4431,7 @@ struct dns_resolv_conf *dns_resconf_open(int *error) {
 	};
 	struct dns_resolv_conf *resconf;
 	struct sockaddr_in *sin;
+	size_t len;
 
 	if (!(resconf = malloc(sizeof *resconf)))
 		goto syerr;
@@ -4436,13 +4449,11 @@ struct dns_resolv_conf *dns_resconf_open(int *error) {
 	if (0 != gethostname(resconf->search[0], sizeof resconf->search[0]))
 		goto syerr;
 
-	dns_d_anchor(resconf->search[0], sizeof resconf->search[0], resconf->search[0], strlen(resconf->search[0]));
-	dns_d_cleave(resconf->search[0], sizeof resconf->search[0], resconf->search[0], strlen(resconf->search[0]));
-
-	/*
-	 * XXX: If gethostname() returned a string without any label
-	 *      separator, then search[0][0] should be NUL.
-	 */
+	len = strlen(resconf->search[0]);
+	len = dns_d_anchor(resconf->search[0], sizeof resconf->search[0], resconf->search[0], len);
+	len = dns_d_cleave(resconf->search[0], sizeof resconf->search[0], resconf->search[0], len);
+	if (1 == len) /* gethostname() returned a string without any label */
+		resconf->search[0][0] = '\0';
 
 	dns_resconf_acquire(resconf);
 
@@ -6115,11 +6126,19 @@ static void dns_socketclose(int *fd, const struct dns_options *opts) {
 #endif
 
 #ifndef HAVE_SOCK_CLOEXEC
-#define HAVE_SOCK_CLOEXEC (defined SOCK_CLOEXEC)
+#ifdef SOCK_CLOEXEC
+#define HAVE_SOCK_CLOEXEC 1
+#else
+#define HAVE_SOCK_CLOEXEC 0
+#endif
 #endif
 
 #ifndef HAVE_SOCK_NONBLOCK
-#define HAVE_SOCK_NONBLOCK (defined SOCK_NONBLOCK)
+#ifdef SOCK_NONBLOCK
+#define HAVE_SOCK_NONBLOCK 1
+#else
+#define HAVE_SOCK_NONBLOCK 0
+#endif
 #endif
 
 #define DNS_SO_MAXTRY	7
@@ -6595,11 +6614,13 @@ int dns_so_check(struct dns_socket *so) {
 	switch (so->state) {
 	case DNS_SO_UDP_INIT:
 		so->state++;
+		/* FALL THROUGH */
 	case DNS_SO_UDP_CONN:
 		if (0 != connect(so->udp, (struct sockaddr *)&so->remote, dns_sa_len(&so->remote)))
 			goto soerr;
 
 		so->state++;
+		/* FALL THROUGH */
 	case DNS_SO_UDP_SEND:
 		if (0 > (n = send(so->udp, (void *)so->query->data, so->query->end, 0)))
 			goto soerr;
@@ -6608,6 +6629,7 @@ int dns_so_check(struct dns_socket *so) {
 		so->stat.udp.sent.count++;
 
 		so->state++;
+		/* FALL THROUGH */
 	case DNS_SO_UDP_RECV:
 		if (0 > (n = recv(so->udp, (void *)so->answer->data, so->answer->size, 0)))
 			goto soerr;
@@ -6622,11 +6644,13 @@ int dns_so_check(struct dns_socket *so) {
 			goto trash;
 
 		so->state++;
+		/* FALL THROUGH */
 	case DNS_SO_UDP_DONE:
 		if (!dns_header(so->answer)->tc || so->type == SOCK_DGRAM)
 			return 0;
 
 		so->state++;
+		/* FALL THROUGH */
 	case DNS_SO_TCP_INIT:
 		if (dns_so_tcp_keep(so)) {
 			so->state = DNS_SO_TCP_SEND;
@@ -6641,6 +6665,7 @@ int dns_so_check(struct dns_socket *so) {
 			goto error;
 
 		so->state++;
+		/* FALL THROUGH */
 	case DNS_SO_TCP_CONN:
 		if (0 != connect(so->tcp, (struct sockaddr *)&so->remote, dns_sa_len(&so->remote))) {
 			if (dns_soerr() != DNS_EISCONN)
@@ -6648,16 +6673,19 @@ int dns_so_check(struct dns_socket *so) {
 		}
 
 		so->state++;
+		/* FALL THROUGH */
 	case DNS_SO_TCP_SEND:
 		if ((error = dns_so_tcp_send(so)))
 			goto error;
 
 		so->state++;
+		/* FALL THROUGH */
 	case DNS_SO_TCP_RECV:
 		if ((error = dns_so_tcp_recv(so)))
 			goto error;
 
 		so->state++;
+		/* FALL THROUGH */
 	case DNS_SO_TCP_DONE:
 		/* close unless DNS_RESCONF_TCP_ONLY (see dns_res_tcp2type) */
 		if (so->type != SOCK_STREAM) {
@@ -7269,6 +7297,7 @@ static int dns_res_exec(struct dns_resolver *R) {
 	switch (F->state) {
 	case DNS_R_INIT:
 		F->state++;
+		/* FALL THROUGH */
 	case DNS_R_GLUE:
 		if (R->sp == 0)
 			dgoto(R->sp, DNS_R_SWITCH);
@@ -7295,6 +7324,7 @@ static int dns_res_exec(struct dns_resolver *R) {
 		}
 
 		F->state++;
+		/* FALL THROUGH */
 	case DNS_R_SWITCH:
 		while (F->which < (int)sizeof R->resconf->lookup && R->resconf->lookup[F->which]) {
 			switch (R->resconf->lookup[F->which++]) {
@@ -7383,16 +7413,19 @@ static int dns_res_exec(struct dns_resolver *R) {
 			goto error;
 
 		F->state++;
+		/* FALL THROUGH */
 	case DNS_R_SUBMIT:
 		if ((error = R->cache->submit(F->query, R->cache)))
 			goto error;
 
 		F->state++;
+		/* FALL THROUGH */
 	case DNS_R_CHECK:
 		if ((error = R->cache->check(R->cache)))
 			goto error;
 
 		F->state++;
+		/* FALL THROUGH */
 	case DNS_R_FETCH:
 		error = 0;
 
@@ -7418,6 +7451,7 @@ static int dns_res_exec(struct dns_resolver *R) {
 		R->search = 0;
 
 		F->state++;
+		/* FALL THROUGH */
 	case DNS_R_SEARCH:
 		/*
 		 * XXX: We probably should only apply the domain search
@@ -7430,11 +7464,13 @@ static int dns_res_exec(struct dns_resolver *R) {
 			goto error;
 
 		F->state++;
+		/* FALL THROUGH */
 	case DNS_R_HINTS:
 		if (!dns_p_setptr(&F->hints, dns_hints_query(R->hints, F->query, &error)))
 			goto error;
 
 		F->state++;
+		/* FALL THROUGH */
 	case DNS_R_ITERATE:
 		dns_rr_i_init(&F->hints_i, F->hints);
 
@@ -7444,6 +7480,7 @@ static int dns_res_exec(struct dns_resolver *R) {
 		F->hints_i.args[0]	= F->hints->end;
 
 		F->state++;
+		/* FALL THROUGH */
 	case DNS_R_FOREACH_NS:
 		dns_rr_i_save(&F->hints_i);
 
@@ -7533,6 +7570,7 @@ static int dns_res_exec(struct dns_resolver *R) {
 
 		F->state++;
 	}
+	/* FALL THROUGH */
 	case DNS_R_QUERY_A:
 		if (dns_so_elapsed(&R->so) >= dns_resconf_timeout(R->resconf))
 			dgoto(R->sp, DNS_R_FOREACH_A);
@@ -7636,6 +7674,7 @@ static int dns_res_exec(struct dns_resolver *R) {
 		dns_rr_i_init(&R->smart, F->answer);
 
 		F->state++;
+		/* FALL THROUGH */
 	case DNS_R_SMART0_A:
 		if (&F[1] >= endof(R->stack))
 			dgoto(R->sp, DNS_R_DONE);
@@ -8281,11 +8320,13 @@ int dns_ai_nextent(struct addrinfo **ent, struct dns_addrinfo *ai) {
 	switch (ai->state) {
 	case DNS_AI_S_INIT:
 		ai->state++;
+		/* FALL THROUGH */
 	case DNS_AI_S_NEXTAF:
 		if (!dns_ai_nextaf(ai))
 			dns_ai_goto(DNS_AI_S_DONE);
 
 		ai->state++;
+		/* FALL THROUGH */
 	case DNS_AI_S_NUMERIC:
 		if (1 == dns_inet_pton(AF_INET, ai->qname, &any.a)) {
 			if (ai->af.atype == AF_INET) {
@@ -8309,6 +8350,7 @@ int dns_ai_nextent(struct addrinfo **ent, struct dns_addrinfo *ai) {
 			dns_ai_goto(DNS_AI_S_NEXTAF);
 
 		ai->state++;
+		/* FALL THROUGH */
 	case DNS_AI_S_SUBMIT:
 		assert(ai->res);
 
@@ -8316,11 +8358,13 @@ int dns_ai_nextent(struct addrinfo **ent, struct dns_addrinfo *ai) {
 			return error;
 
 		ai->state++;
+		/* FALL THROUGH */
 	case DNS_AI_S_CHECK:
 		if ((error = dns_res_check(ai->res)))
 			return error;
 
 		ai->state++;
+		/* FALL THROUGH */
 	case DNS_AI_S_FETCH:
 		if (!(ans = dns_res_fetch_and_study(ai->res, &error)))
 			return error;
@@ -8344,6 +8388,7 @@ int dns_ai_nextent(struct addrinfo **ent, struct dns_addrinfo *ai) {
 		ai->i.sort    = &dns_rr_i_order;
 
 		ai->state++;
+		/* FALL THROUGH */
 	case DNS_AI_S_FOREACH_I:
 		if (!dns_rr_grep(&rr, 1, &ai->i, ai->answer, &error))
 			dns_ai_goto(DNS_AI_S_NEXTAF);
@@ -8378,10 +8423,12 @@ int dns_ai_nextent(struct addrinfo **ent, struct dns_addrinfo *ai) {
 		} /* switch() */
 
 		ai->state++;
+		/* FALL THROUGH */
 	case DNS_AI_S_INIT_G:
 		ai->g_depth = 0;
 
 		ai->state++;
+		/* FALL THROUGH */
 	case DNS_AI_S_ITERATE_G:
 		dns_strlcpy(ai->g_cname, ai->cname, sizeof ai->g_cname);
 		dns_rr_i_init(&ai->g, ai->glue);
@@ -8390,6 +8437,7 @@ int dns_ai_nextent(struct addrinfo **ent, struct dns_addrinfo *ai) {
 		ai->g.type    = ai->af.qtype;
 
 		ai->state++;
+		/* FALL THROUGH */
 	case DNS_AI_S_FOREACH_G:
 		if (!dns_rr_grep(&rr, 1, &ai->g, ai->glue, &error)) {
 			if (dns_rr_i_count(&ai->g) > 0)
@@ -8414,11 +8462,13 @@ int dns_ai_nextent(struct addrinfo **ent, struct dns_addrinfo *ai) {
 			return error;
 
 		ai->state++;
+		/* FALL THROUGH */
 	case DNS_AI_S_CHECK_G:
 		if ((error = dns_res_check(ai->res)))
 			return error;
 
 		ai->state++;
+		/* FALL THROUGH */
 	case DNS_AI_S_FETCH_G:
 		if (!(ans = dns_res_fetch_and_study(ai->res, &error)))
 			return error;