Skip to content

Commit

Permalink
fix dns parsing for unknown header types
Browse files Browse the repository at this point in the history
  • Loading branch information
DarienRaymond committed Feb 21, 2019
1 parent 9957c64 commit bb8465e
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions app/dns/udpns.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ package dns
import (
"context"
"encoding/binary"
fmt "fmt"
"sync"
"sync/atomic"
"time"
Expand Down Expand Up @@ -163,6 +162,7 @@ func (s *ClassicNameServer) HandleResponse(ctx context.Context, packet *udp_prot
Expire: now.Add(time.Second * 600),
}

L:
for {
header, err := parser.AnswerHeader()
if err != nil {
Expand All @@ -181,6 +181,10 @@ func (s *ClassicNameServer) HandleResponse(ctx context.Context, packet *udp_prot
}

if header.Type != recType {
if err := parser.SkipAnswer(); err != nil {
newError("failed to skip answer").Base(err).WriteToLog()
break L
}
continue
}

Expand All @@ -189,19 +193,20 @@ func (s *ClassicNameServer) HandleResponse(ctx context.Context, packet *udp_prot
ans, err := parser.AResource()
if err != nil {
newError("failed to parse A record for domain: ", domain).Base(err).WriteToLog()
break
break L
}
ipRecord.IP = append(ipRecord.IP, net.IPAddress(ans.A[:]))
case dnsmessage.TypeAAAA:
ans, err := parser.AAAAResource()
if err != nil {
newError("failed to parse A record for domain: ", domain).Base(err).WriteToLog()
break
break L
}
ipRecord.IP = append(ipRecord.IP, net.IPAddress(ans.AAAA[:]))
default:
if err := parser.SkipAnswer(); err != nil {
newError("failed to skip answer").Base(err).WriteToLog()
break L
}
}
}
Expand Down Expand Up @@ -399,8 +404,6 @@ func (s *ClassicNameServer) findIPsForDomain(domain string, option IPOption) ([]
ips = append(ips, aaaa...)
}

fmt.Println("IPs for ", domain, ": ", ips)

if len(ips) > 0 {
return toNetIP(ips), nil
}
Expand Down

0 comments on commit bb8465e

Please sign in to comment.