Skip to content

Commit

Permalink
fix: check type assertion fails / avoid assertions
Browse files Browse the repository at this point in the history
  • Loading branch information
developStorm committed Nov 12, 2024
1 parent b036b60 commit ca7dc81
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
6 changes: 3 additions & 3 deletions src/zdns/answers.go
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ func makeEDNSAnswer(cAns *dns.OPT) EDNSAnswer {
KeyLease: opt.KeyLease,
}
case *dns.EDNS0_NSID: //OPT 3
hexDecoded, err := hex.DecodeString(o.(*dns.EDNS0_NSID).Nsid)
hexDecoded, err := hex.DecodeString(opt.Nsid)
if err != nil {
continue
}
Expand Down Expand Up @@ -443,15 +443,15 @@ func makeEDNSAnswer(cAns *dns.OPT) EDNSAnswer {
Expire: opt.Expire,
}
case *dns.EDNS0_COOKIE: //OPT 11
optRes.Cookie = &Edns0Cookie{Cookie: o.(*dns.EDNS0_COOKIE).Cookie}
optRes.Cookie = &Edns0Cookie{Cookie: opt.Cookie}
case *dns.EDNS0_TCP_KEEPALIVE: //OPT 11
optRes.TCPKeepalive = &Edns0TCPKeepalive{
Code: opt.Code,
Timeout: opt.Timeout,
Length: opt.Length, // deprecated, always equal to 0, keeping it here for a better readability
}
case *dns.EDNS0_PADDING: //OPT 12
optRes.Padding = &Edns0Padding{Padding: o.(*dns.EDNS0_PADDING).String()}
optRes.Padding = &Edns0Padding{Padding: opt.String()}
case *dns.EDNS0_EDE: //OPT 15
optRes.EDE = append(optRes.EDE, &Edns0Ede{
InfoCode: opt.InfoCode,
Expand Down
8 changes: 7 additions & 1 deletion src/zdns/resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,13 @@ func (r *Resolver) getConnectionInfo(nameServer *NameServer) (*ConnectionInfo, e
if err != nil {
return nil, fmt.Errorf("unable to find default IP address to open socket: %w", err)
}
localAddr = &conn.LocalAddr().(*net.UDPAddr).IP

localUDPAddr, ok := conn.LocalAddr().(*net.UDPAddr)
if !ok {
return nil, errors.New("unable to get local address from connection")
}
localAddr = &localUDPAddr.IP

// cleanup socket
if err = conn.Close(); err != nil {
log.Error("unable to close test connection to Google public DNS: ", err)
Expand Down

0 comments on commit ca7dc81

Please sign in to comment.