From 24a04d07d13bd8bdbbf2737f2cc5a19fee8ff087 Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Wed, 12 Jan 2022 12:30:25 -0800 Subject: [PATCH] net/dns/resolver: handle tabs as whitespace when ExitDNS parses resolv.conf On Synology, the /etc/resolv.conf has tabs in it, which this resolv.conf parser (we have two, sigh) didn't handle. Updates #3710 Change-Id: I86f8e09ad1867ee32fa211e85c382a27191418ea Signed-off-by: Brad Fitzpatrick --- net/dns/resolver/tsdns.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/net/dns/resolver/tsdns.go b/net/dns/resolver/tsdns.go index 4d75c18d5..b36633a13 100644 --- a/net/dns/resolver/tsdns.go +++ b/net/dns/resolver/tsdns.go @@ -529,6 +529,10 @@ func stubResolverForOS() (ip netaddr.IP, err error) { if c, ok := resolvConfCacheValue.Load().(resolvConfCache); ok && c.mod == cur.mod && c.size == cur.size { return c.ip, nil } + // TODO(bradfitz): unify this /etc/resolv.conf parsing code with readResolv + // in net/dns, which we can't use due to circular dependency reasons. + // Move it to a leaf, including the OSConfig type (perhaps in its own dnstype + // package?) err = lineread.File("/etc/resolv.conf", func(line []byte) error { if !ip.IsZero() { return nil @@ -537,6 +541,12 @@ func stubResolverForOS() (ip netaddr.IP, err error) { if len(line) == 0 || line[0] == '#' { return nil } + // Normalize tabs to spaces to simplify parsing code later. + for i, b := range line { + if b == '\t' { + line[i] = ' ' + } + } if mem.HasPrefix(mem.B(line), mem.S("nameserver ")) { s := strings.TrimSpace(strings.TrimPrefix(string(line), "nameserver ")) ip, err = netaddr.ParseIP(s)