Prevent panic when write packet with bad address type
This commit is contained in:
parent
323b9564f0
commit
d51abeb6c7
1 changed files with 7 additions and 0 deletions
|
|
@ -13,6 +13,7 @@ import (
|
||||||
"github.com/sagernet/gvisor/pkg/tcpip/header"
|
"github.com/sagernet/gvisor/pkg/tcpip/header"
|
||||||
"github.com/sagernet/gvisor/pkg/tcpip/stack"
|
"github.com/sagernet/gvisor/pkg/tcpip/stack"
|
||||||
"github.com/sagernet/sing/common/buf"
|
"github.com/sagernet/sing/common/buf"
|
||||||
|
E "github.com/sagernet/sing/common/exceptions"
|
||||||
M "github.com/sagernet/sing/common/metadata"
|
M "github.com/sagernet/sing/common/metadata"
|
||||||
N "github.com/sagernet/sing/common/network"
|
N "github.com/sagernet/sing/common/network"
|
||||||
"github.com/sagernet/sing/common/udpnat"
|
"github.com/sagernet/sing/common/udpnat"
|
||||||
|
|
@ -62,6 +63,12 @@ type UDPBackWriter struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *UDPBackWriter) WritePacket(packetBuffer *buf.Buffer, destination M.Socksaddr) error {
|
func (w *UDPBackWriter) WritePacket(packetBuffer *buf.Buffer, destination M.Socksaddr) error {
|
||||||
|
if destination.IsIPv4() && w.sourceNetwork == header.IPv6ProtocolNumber {
|
||||||
|
destination = M.SocksaddrFrom(netip.AddrFrom16(destination.Addr.As16()), destination.Port)
|
||||||
|
} else if destination.IsIPv6() && (w.sourceNetwork == header.IPv4AddressSizeBits) {
|
||||||
|
return E.New("send IPv6 packet to IPv4 connection")
|
||||||
|
}
|
||||||
|
|
||||||
defer packetBuffer.Release()
|
defer packetBuffer.Release()
|
||||||
|
|
||||||
route, err := w.stack.FindRoute(
|
route, err := w.stack.FindRoute(
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue