Skip to content

Commit

Permalink
Fix fatal error processing unexpected records (#1)
Browse files Browse the repository at this point in the history
by adding a type assertion guard.
  • Loading branch information
neomantra committed Apr 16, 2023
1 parent 31a0b10 commit 70c2243
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 15 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
Changelog
=========

## v0.4.0 (2023-04-12)
## v0.4.0 (2023-04-16)

* Add `-a` and `-6` to check A/AAAA instead of SRV records
* Fix fatal error processing unexpected records (#1)
* Custom DNS (--dns) can now be specified without port (appends :53)

## v0.3.0 (2023-03-31)

Expand Down
29 changes: 15 additions & 14 deletions pkg/lookup/loopkup_srv.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,22 +69,23 @@ func LookupSRVCustom(name string, dnsResolver string, recurse bool) ([]*dns.SRV,
}
var records []*dns.SRV
for _, ans := range r.Answer {
srvRecord := *ans.(*dns.SRV)
if recurse && net.ParseIP(srvRecord.Target) == nil {
m2 := dns.Msg{}
m2.SetQuestion(srvRecord.Target, dns.TypeA)
m2.RecursionDesired = true
r2, _, err := c.Exchange(&m2, dnsResolver)
if err != nil {
fmt.Fprintf(os.Stderr, "error: %v\n", err)
return nil, err
}
if len(r2.Answer) != 0 {
aRecord := r2.Answer[0].(*dns.A)
srvRecord.Target = aRecord.A.String()
if srvRecord, ok := ans.(*dns.SRV); ok && srvRecord != nil {
if recurse && net.ParseIP(srvRecord.Target) == nil {
m2 := dns.Msg{}
m2.SetQuestion(srvRecord.Target, dns.TypeA)
m2.RecursionDesired = true
r2, _, err := c.Exchange(&m2, dnsResolver)
if err != nil {
fmt.Fprintf(os.Stderr, "error: %v\n", err)
return nil, err
}
if len(r2.Answer) != 0 {
aRecord := r2.Answer[0].(*dns.A)
srvRecord.Target = aRecord.A.String()
}
}
records = append(records, srvRecord)
}
records = append(records, &srvRecord)
}
return records, nil
}

0 comments on commit 70c2243

Please sign in to comment.