Skip to content

Commit 70c2243

Browse files
committed
Fix fatal error processing unexpected records (#1)
by adding a type assertion guard.
1 parent 31a0b10 commit 70c2243

File tree

2 files changed

+18
-15
lines changed

2 files changed

+18
-15
lines changed

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
Changelog
22
=========
33

4-
## v0.4.0 (2023-04-12)
4+
## v0.4.0 (2023-04-16)
55

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

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

pkg/lookup/loopkup_srv.go

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -69,22 +69,23 @@ func LookupSRVCustom(name string, dnsResolver string, recurse bool) ([]*dns.SRV,
6969
}
7070
var records []*dns.SRV
7171
for _, ans := range r.Answer {
72-
srvRecord := *ans.(*dns.SRV)
73-
if recurse && net.ParseIP(srvRecord.Target) == nil {
74-
m2 := dns.Msg{}
75-
m2.SetQuestion(srvRecord.Target, dns.TypeA)
76-
m2.RecursionDesired = true
77-
r2, _, err := c.Exchange(&m2, dnsResolver)
78-
if err != nil {
79-
fmt.Fprintf(os.Stderr, "error: %v\n", err)
80-
return nil, err
81-
}
82-
if len(r2.Answer) != 0 {
83-
aRecord := r2.Answer[0].(*dns.A)
84-
srvRecord.Target = aRecord.A.String()
72+
if srvRecord, ok := ans.(*dns.SRV); ok && srvRecord != nil {
73+
if recurse && net.ParseIP(srvRecord.Target) == nil {
74+
m2 := dns.Msg{}
75+
m2.SetQuestion(srvRecord.Target, dns.TypeA)
76+
m2.RecursionDesired = true
77+
r2, _, err := c.Exchange(&m2, dnsResolver)
78+
if err != nil {
79+
fmt.Fprintf(os.Stderr, "error: %v\n", err)
80+
return nil, err
81+
}
82+
if len(r2.Answer) != 0 {
83+
aRecord := r2.Answer[0].(*dns.A)
84+
srvRecord.Target = aRecord.A.String()
85+
}
8586
}
87+
records = append(records, srvRecord)
8688
}
87-
records = append(records, &srvRecord)
8889
}
8990
return records, nil
9091
}

0 commit comments

Comments
 (0)