chore: discard domain addr input in sudoku uot

This commit is contained in:
wwqgtxx
2025-12-03 22:49:31 +08:00
parent 30891f8781
commit 32ce513977
2 changed files with 9 additions and 3 deletions

View File

@@ -5,6 +5,7 @@ import (
"fmt"
"io"
"net"
"strconv"
)
func EncodeAddress(rawAddr string) ([]byte, error) {
@@ -13,7 +14,7 @@ func EncodeAddress(rawAddr string) ([]byte, error) {
return nil, err
}
portInt, err := net.LookupPort("udp", portStr)
portInt, err := strconv.ParseUint(portStr, 10, 16)
if err != nil {
return nil, err
}

View File

@@ -7,6 +7,8 @@ import (
"fmt"
"io"
"net"
"net/netip"
"strconv"
"sync"
"time"
@@ -109,11 +111,14 @@ func (c *UoTPacketConn) ReadFrom(p []byte) (int, net.Addr, error) {
return 0, nil, io.ErrShortBuffer
}
udpAddr, err := net.ResolveUDPAddr("udp", addrStr)
if err != nil {
host, port, _ := net.SplitHostPort(addrStr)
portInt, _ := strconv.ParseUint(port, 10, 16)
ip, err := netip.ParseAddr(host)
if err != nil { // disallow domain addr at here, just ignore
log.Debugln("[Sudoku][UoT] discard datagram with invalid address %s: %v", addrStr, err)
continue
}
udpAddr := net.UDPAddrFromAddrPort(netip.AddrPortFrom(ip.Unmap(), uint16(portInt)))
copy(p, payload)
return len(payload), udpAddr, nil