aboutsummaryrefslogtreecommitdiffstats
path: root/main/musl/1000-resolv.conf-shenanigans.patch
blob: d6261572f850aecda3d1611d191ba3abf1fc40a3 (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
From b5fd71a0dfb8e7e32a46458abe701f7cd8ebc77b Mon Sep 17 00:00:00 2001
From: William Pitcock <nenolod@dereferenced.org>
Date: Fri, 30 Mar 2018 10:45:01 +0000
Subject: [PATCH] resolv.conf parser: concatenate multiple search domain lines

Programs such as Docker and Kubernetes write multiple domain search lines, such as

search serious-business.big-data.prod.foo.com
search big-data.prod.foo.com
search prod.foo.com

instead of

search serious-business.big-data.prod.foo.com big-data.prod.foo.com prod.foo.com

Accordingly, we concatenate the namelist together so that the search path is
not truncated.

(Sorry, not sorry, for ruining the "omg Alpine sucks at DNS" talk at Kubecon)
---
 src/network/lookup_name.c | 2 +-
 src/network/resolvconf.c  | 7 ++++++-
 2 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/src/network/lookup_name.c b/src/network/lookup_name.c
index 209c20f0..c83c11c5 100644
--- a/src/network/lookup_name.c
+++ b/src/network/lookup_name.c
@@ -172,7 +172,7 @@ static int name_from_dns(struct address buf[static MAXADDRS], char canon[static
 
 static int name_from_dns_search(struct address buf[static MAXADDRS], char canon[static 256], const char *name, int family)
 {
-	char search[256];
+	char search[2048];
 	struct resolvconf conf;
 	size_t l, dots;
 	char *p, *z;
diff --git a/src/network/resolvconf.c b/src/network/resolvconf.c
index 4c3e4c4b..72ed4082 100644
--- a/src/network/resolvconf.c
+++ b/src/network/resolvconf.c
@@ -9,6 +9,7 @@ int __get_resolv_conf(struct resolvconf *conf, char *search, size_t search_sz)
 {
 	char line[256];
 	unsigned char _buf[256];
+	char *search_base = search;
 	FILE *f, _f;
 	int nns = 0;
 
@@ -74,9 +75,13 @@ int __get_resolv_conf(struct resolvconf *conf, char *search, size_t search_sz)
 			continue;
 		for (p=line+7; isspace(*p); p++);
 		size_t l = strlen(p);
+		ptrdiff_t m = search - search_base;
 		/* This can never happen anyway with chosen buffer sizes. */
-		if (l >= search_sz) continue;
+		if (l + m >= search_sz) continue;
 		memcpy(search, p, l+1);
+		/* We concatenate the search list as domain1 domain2\0 */
+		search += l;
+		*search++ = ' ';
 	}
 
 	__fclose_ca(f);
-- 
2.16.2