fix: tunnel's handleUDPToLocal panic
This commit is contained in:
parent
9cbca162a0
commit
9b50f56e7c
1 changed files with 7 additions and 4 deletions
|
@ -41,7 +41,13 @@ func handleUDPToLocal(writeBack C.WriteBack, pc N.EnhancePacketConn, key string,
|
||||||
}
|
}
|
||||||
|
|
||||||
fromUDPAddr, isUDPAddr := from.(*net.UDPAddr)
|
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
|
||||||
fromUDPAddr = &_fromUDPAddr // make a copy
|
fromUDPAddr = &_fromUDPAddr // make a copy
|
||||||
if fromAddr, ok := netip.AddrFromSlice(fromUDPAddr.IP); ok {
|
if fromAddr, ok := netip.AddrFromSlice(fromUDPAddr.IP); ok {
|
||||||
|
@ -54,9 +60,6 @@ func handleUDPToLocal(writeBack C.WriteBack, pc N.EnhancePacketConn, key string,
|
||||||
fromUDPAddr.Zone = "" // only ipv6 can have the zone
|
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)
|
_, err = writeBack.WriteBack(data, fromUDPAddr)
|
||||||
|
|
Loading…
Reference in a new issue