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 3a214b6
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(
fmt.Sprintf("unable to get nameserver"),

Check failure on line 175 in internal/dns/dns.go

View workflow job for this annotation

GitHub Actions / lint

S1039: unnecessary use of fmt.Sprintf (gosimple)
)
}
slog.Error(
fmt.Sprintf("unable to get nameserver"),

Check failure on line 179 in internal/dns/dns.go

View workflow job for this annotation

GitHub Actions / lint

S1039: unnecessary use of fmt.Sprintf (gosimple)
)
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 3a214b6

Please sign in to comment.