Skip to content

Commit

Permalink
fix tunnel's handleUDPToLocal panic
Browse files Browse the repository at this point in the history
  • Loading branch information
wwqgtxx committed Jul 16, 2023
1 parent f2b3c06 commit ab2785d
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions tunnel/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,13 @@ func handleUDPToLocal(writeBack C.WriteBack, pc N.EnhancePacketConn, key string,
}

fromUDPAddr, isUDPAddr := from.(*net.UDPAddr)
if isUDPAddr {
if !isUDPAddr {
fromUDPAddr = net.UDPAddrFromAddrPort(oAddrPort) // oAddrPort was Unmapped
log.Warnln("server return a [%T](%s) which isn't a *net.UDPAddr, force replace to (%s), this may be caused by a wrongly implemented server", from, from, oAddrPort)
} else if fromUDPAddr == nil {
fromUDPAddr = net.UDPAddrFromAddrPort(oAddrPort) // oAddrPort was Unmapped
log.Warnln("server return a nil *net.UDPAddr, force replace to (%s), this may be caused by a wrongly implemented server", oAddrPort)
} else {
_fromUDPAddr := *fromUDPAddr
fromUDPAddr = &_fromUDPAddr // make a copy
if fromAddr, ok := netip.AddrFromSlice(fromUDPAddr.IP); ok {
Expand All @@ -56,9 +62,6 @@ func handleUDPToLocal(writeBack C.WriteBack, pc N.EnhancePacketConn, key string,
fromUDPAddr.Zone = "" // only ipv6 can have the zone
}
}
} else {
fromUDPAddr = net.UDPAddrFromAddrPort(oAddrPort) // oAddrPort was Unmapped
log.Warnln("server return a [%T](%s) which isn't a *net.UDPAddr, force replace to (%s), this may be caused by a wrongly implemented server", from, from, oAddrPort)
}

_, err = writeBack.WriteBack(data, fromUDPAddr)
Expand Down

0 comments on commit ab2785d

Please sign in to comment.