1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-12-22 01:57:12 -05:00

drop unsupported domain address type in packet addr (#3186)

This commit is contained in:
Xiaokang Wang (Shelikhoo) 2024-10-12 19:25:59 +01:00 committed by GitHub
parent 05345cc4fd
commit 229b30d877
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 15 additions and 0 deletions

View File

@ -79,6 +79,11 @@ func (c *packetConnectionAdaptor) ReadFrom(p []byte) (n int, addr gonet.Addr, er
}
func (c *packetConnectionAdaptor) WriteTo(p []byte, addr gonet.Addr) (n int, err error) {
_, ok := addr.(*gonet.UDPAddr)
if !ok {
// address other than UDPAddr is not supported, and will be dropped.
return 0, nil
}
payloadLen := len(p)
var buffer *buf.Buffer
buffer, err = AttachAddressToPacket(buf.FromBytes(p), addr)

View File

@ -2,6 +2,7 @@ package packetaddr
import (
"bytes"
"github.com/v2fly/v2ray-core/v5/common/errors"
gonet "net"
"github.com/v2fly/v2ray-core/v5/common/buf"
@ -45,6 +46,9 @@ func ExtractAddressFromPacket(data *buf.Buffer) (*buf.Buffer, gonet.Addr, error)
if err != nil {
return nil, nil, err
}
if address.Family().IsDomain() {
return nil, nil, errors.New("invalid address type")
}
addr := &gonet.UDPAddr{
IP: address.IP(),
Port: int(port.Value()),

View File

@ -27,6 +27,12 @@ func (p PacketAddrDispatcher) Dispatch(ctx context.Context, destination net.Dest
if destination.Network != net.Network_UDP {
return
}
// Processing of domain address is unsupported as it adds unpredictable overhead, it will be dropped.
if destination.Address.Family().IsDomain() {
return
}
p.conn.WriteTo(payload.Bytes(), &net.UDPAddr{IP: destination.Address.IP(), Port: int(destination.Port.Value())})
}