Skip to content

Commit

Permalink
fix: guard against nil before calling string
Browse files Browse the repository at this point in the history
Signed-off-by: Chris Gianelloni <[email protected]>
  • Loading branch information
wolf31o2 committed Nov 18, 2024
1 parent 4082866 commit 65f3373
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions internal/dns/dns.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ func startListener(server *dns.Server) {
}

func handleQuery(w dns.ResponseWriter, r *dns.Msg) {
if r.Question == nil {
return
}
cfg := config.GetConfig()
m := new(dns.Msg)

Expand Down Expand Up @@ -165,6 +168,18 @@ func handleQuery(w dns.ResponseWriter, r *dns.Msg) {
if cfg.Dns.RecursionEnabled {
// Pick random nameserver for domain
tmpNameserver := randomNameserverAddress(nameservers)
if tmpNameserver == nil {
m.SetRcode(r, dns.RcodeServerFailure)
if err := w.WriteMsg(m); err != nil {
slog.Error(
"unable to get nameserver",
)
}
slog.Error(
"unable to get nameserver",
)
return
}
// Query the random domain nameserver we picked above
resp, err := doQuery(r, tmpNameserver.String(), true)
if err != nil {
Expand Down Expand Up @@ -469,9 +484,13 @@ func getAddressForNameFromResponse(msg *dns.Msg, recordName string) string {
}
switch v := retRR.(type) {
case *dns.A:
return v.A.String()
if v.A != nil {
return v.A.String()
}
case *dns.AAAA:
return v.AAAA.String()
if v.AAAA != nil {
return v.AAAA.String()
}
}
return ""
}
Expand Down

0 comments on commit 65f3373

Please sign in to comment.