Skip to content

Commit

Permalink
fix: Handle /etc/resolv.conf more cautiously
Browse files Browse the repository at this point in the history
On my machine, `dhcpcd` had taken control of /etc/resolv.conf and
populated it with nothing but comments. This led to a runtime panic as
`conf.Servers` was well-defined, but empty. This commit adds handling
for this case.
  • Loading branch information
adamroyjones committed Sep 28, 2022
1 parent 13573e3 commit 67758c3
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ All long form (--) flags can be toggled with the dig-standard +[no]flag notation
}

// Parse requested RR types
var rrTypes = make(map[uint16]bool)
rrTypes := make(map[uint16]bool)
for _, rrType := range opts.Types {
typeCode, ok := dns.StringToType[strings.ToUpper(rrType)]
if ok {
Expand Down Expand Up @@ -429,8 +429,13 @@ All long form (--) flags can be toggled with the dig-standard +[no]flag notation
opts.Server = "https://cloudflare-dns.com/dns-query"
log.Debugf("no server set, using %s", opts.Server)
} else {
opts.Server = conf.Servers[0]
log.Debugf("found server %s from /etc/resolv.conf", opts.Server)
if len(conf.Servers) == 0 {
opts.Server = "https://cloudflare-dns.com/dns-query"
log.Debugf("no server set, using %s", opts.Server)
} else {
opts.Server = conf.Servers[0]
log.Debugf("found server %s from /etc/resolv.conf", opts.Server)
}
}
}

Expand Down

0 comments on commit 67758c3

Please sign in to comment.