Fix a panic condition
parent
08b93ecec3
commit
b6ffce37c3
|
@ -83,7 +83,7 @@ func (s *Server) handleRequest(conn conn, bufConn io.Reader) error {
|
||||||
if dest.fqdn != "" {
|
if dest.fqdn != "" {
|
||||||
addr, err := s.config.Resolver.Resolve(dest.fqdn)
|
addr, err := s.config.Resolver.Resolve(dest.fqdn)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if err := sendReply(conn, hostUnreachable, nil); err != nil {
|
if err := sendReply(conn, hostUnreachable, dest); err != nil {
|
||||||
return fmt.Errorf("Failed to send reply: %v", err)
|
return fmt.Errorf("Failed to send reply: %v", err)
|
||||||
}
|
}
|
||||||
return fmt.Errorf("Failed to resolve destination '%v': %v", dest.fqdn, err)
|
return fmt.Errorf("Failed to resolve destination '%v': %v", dest.fqdn, err)
|
||||||
|
@ -246,6 +246,7 @@ func sendReply(w io.Writer, resp uint8, addr *addrSpec) error {
|
||||||
// Format the address
|
// Format the address
|
||||||
var addrType uint8
|
var addrType uint8
|
||||||
var addrBody []byte
|
var addrBody []byte
|
||||||
|
var addrPort uint16
|
||||||
switch {
|
switch {
|
||||||
case addr == nil:
|
case addr == nil:
|
||||||
addrType = 0
|
addrType = 0
|
||||||
|
@ -254,14 +255,17 @@ func sendReply(w io.Writer, resp uint8, addr *addrSpec) error {
|
||||||
case addr.fqdn != "":
|
case addr.fqdn != "":
|
||||||
addrType = fqdnAddress
|
addrType = fqdnAddress
|
||||||
addrBody = append([]byte{byte(len(addr.fqdn))}, addr.fqdn...)
|
addrBody = append([]byte{byte(len(addr.fqdn))}, addr.fqdn...)
|
||||||
|
addrPort = uint16(addr.port)
|
||||||
|
|
||||||
case addr.ip.To4() != nil:
|
case addr.ip.To4() != nil:
|
||||||
addrType = ipv4Address
|
addrType = ipv4Address
|
||||||
addrBody = []byte(addr.ip.To4())
|
addrBody = []byte(addr.ip.To4())
|
||||||
|
addrPort = uint16(addr.port)
|
||||||
|
|
||||||
case addr.ip.To16() != nil:
|
case addr.ip.To16() != nil:
|
||||||
addrType = ipv6Address
|
addrType = ipv6Address
|
||||||
addrBody = []byte(addr.ip.To16())
|
addrBody = []byte(addr.ip.To16())
|
||||||
|
addrPort = uint16(addr.port)
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return fmt.Errorf("Failed to format address: %v", addr)
|
return fmt.Errorf("Failed to format address: %v", addr)
|
||||||
|
@ -274,7 +278,7 @@ func sendReply(w io.Writer, resp uint8, addr *addrSpec) error {
|
||||||
msg[2] = 0 // Reserved
|
msg[2] = 0 // Reserved
|
||||||
msg[3] = addrType
|
msg[3] = addrType
|
||||||
copy(msg[4:], addrBody)
|
copy(msg[4:], addrBody)
|
||||||
binary.BigEndian.PutUint16(msg[4+len(addrBody):], uint16(addr.port))
|
binary.BigEndian.PutUint16(msg[4+len(addrBody):], uint16(addrPort))
|
||||||
|
|
||||||
// Send the message
|
// Send the message
|
||||||
_, err := w.Write(msg)
|
_, err := w.Write(msg)
|
||||||
|
|
Loading…
Reference in New Issue