Skip to content

Commit

Permalink
Pull request 249: 5631-lookup-panic
Browse files Browse the repository at this point in the history
Merge in GO/dnsproxy from 5631-lookup-panic to master

Updates AdguardTeam/AdGuardHome#5631.

Squashed commit of the following:

commit 8835572
Author: Eugene Burkov <E.Burkov@AdGuard.COM>
Date:   Fri Mar 24 20:11:30 2023 +0500

    proxy: imp doc

commit db08d96
Author: Eugene Burkov <E.Burkov@AdGuard.COM>
Date:   Fri Mar 24 20:08:11 2023 +0500

    proxy: fix lookup slicing
  • Loading branch information
EugeneOne1 committed Mar 24, 2023
1 parent f9672a9 commit 8ae0746
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions proxy/lookup.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"net"

"github.com/AdguardTeam/dnsproxy/proxyutil"
"github.com/AdguardTeam/golibs/errors"

"github.com/miekg/dns"
)
Expand Down Expand Up @@ -31,13 +32,19 @@ func (p *Proxy) lookupIPAddr(host string, qtype uint16, ch chan *lookupResult) {
ch <- &lookupResult{d.Res, err}
}

// ErrEmptyHost is returned by LookupIPAddr when the host is empty and can't be
// resolved.
const ErrEmptyHost = errors.Error("host is empty")

// LookupIPAddr resolves the specified host IP addresses
// It sends two DNS queries (A and AAAA) in parallel and returns both results
func (p *Proxy) LookupIPAddr(host string) ([]net.IPAddr, error) {
if host[:1] != "." {
host += "."
if host == "" {
return nil, ErrEmptyHost
}

host = dns.Fqdn(host)

ch := make(chan *lookupResult)
go p.lookupIPAddr(host, dns.TypeA, ch)
go p.lookupIPAddr(host, dns.TypeAAAA, ch)
Expand Down

0 comments on commit 8ae0746

Please sign in to comment.