From d40e5e4fe6c11311ee1de82779a985c3ca47d03a Mon Sep 17 00:00:00 2001 From: Dreamacro <8615343+Dreamacro@users.noreply.github.com> Date: Mon, 8 Nov 2021 00:31:08 +0800 Subject: [PATCH] Fix: codeql alerts --- adapter/outbound/snell.go | 4 ++-- adapter/outbound/util.go | 2 +- adapter/outbound/vmess.go | 2 +- component/dialer/bind_others.go | 4 ++-- constant/metadata.go | 4 ++-- rule/port.go | 2 +- 6 files changed, 9 insertions(+), 9 deletions(-) diff --git a/adapter/outbound/snell.go b/adapter/outbound/snell.go index 40dcf06649..d0a26ecc1a 100644 --- a/adapter/outbound/snell.go +++ b/adapter/outbound/snell.go @@ -52,7 +52,7 @@ func streamConn(c net.Conn, option streamOption) *snell.Snell { // StreamConn implements C.ProxyAdapter func (s *Snell) StreamConn(c net.Conn, metadata *C.Metadata) (net.Conn, error) { c = streamConn(c, streamOption{s.psk, s.version, s.addr, s.obfsOption}) - port, _ := strconv.Atoi(metadata.DstPort) + port, _ := strconv.ParseInt(metadata.DstPort, 10, 16) err := snell.WriteHeader(c, metadata.String(), uint(port), s.version) return c, err } @@ -65,7 +65,7 @@ func (s *Snell) DialContext(ctx context.Context, metadata *C.Metadata, opts ...d return nil, err } - port, _ := strconv.Atoi(metadata.DstPort) + port, _ := strconv.ParseUint(metadata.DstPort, 10, 16) if err = snell.WriteHeader(c, metadata.String(), uint(port), s.version); err != nil { c.Close() return nil, err diff --git a/adapter/outbound/util.go b/adapter/outbound/util.go index 0e1d4c8e5a..b376522fa7 100644 --- a/adapter/outbound/util.go +++ b/adapter/outbound/util.go @@ -21,7 +21,7 @@ func tcpKeepAlive(c net.Conn) { func serializesSocksAddr(metadata *C.Metadata) []byte { var buf [][]byte aType := uint8(metadata.AddrType) - p, _ := strconv.Atoi(metadata.DstPort) + p, _ := strconv.ParseUint(metadata.DstPort, 10, 16) port := []byte{uint8(p >> 8), uint8(p & 0xff)} switch metadata.AddrType { case socks5.AtypDomainName: diff --git a/adapter/outbound/vmess.go b/adapter/outbound/vmess.go index 6746eb5189..99ea531ca9 100644 --- a/adapter/outbound/vmess.go +++ b/adapter/outbound/vmess.go @@ -353,7 +353,7 @@ func parseVmessAddr(metadata *C.Metadata) *vmess.DstAddr { copy(addr[1:], []byte(metadata.Host)) } - port, _ := strconv.Atoi(metadata.DstPort) + port, _ := strconv.ParseUint(metadata.DstPort, 10, 16) return &vmess.DstAddr{ UDP: metadata.NetWork == C.UDP, AddrType: addrType, diff --git a/component/dialer/bind_others.go b/component/dialer/bind_others.go index 7f1923aa2e..e94946739b 100644 --- a/component/dialer/bind_others.go +++ b/component/dialer/bind_others.go @@ -62,7 +62,7 @@ func bindIfaceToDialer(ifaceName string, dialer *net.Dialer, network string, des if dialer.LocalAddr != nil { _, port, err := net.SplitHostPort(dialer.LocalAddr.String()) if err == nil { - local, _ = strconv.Atoi(port) + local, _ = strconv.ParseInt(port, 10, 16) } } @@ -82,7 +82,7 @@ func bindIfaceToListenConfig(ifaceName string, _ *net.ListenConfig, network, add port = "0" } - local, _ := strconv.Atoi(port) + local, _ := strconv.ParseInt(port, 10, 16) addr, err := lookupLocalAddr(ifaceName, network, nil, local) if err != nil { diff --git a/constant/metadata.go b/constant/metadata.go index 822b4714d3..9cc49973f9 100644 --- a/constant/metadata.go +++ b/constant/metadata.go @@ -107,10 +107,10 @@ func (m *Metadata) UDPAddr() *net.UDPAddr { if m.NetWork != UDP || m.DstIP == nil { return nil } - port, _ := strconv.Atoi(m.DstPort) + port, _ := strconv.ParseInt(m.DstPort, 10, 16) return &net.UDPAddr{ IP: m.DstIP, - Port: port, + Port: int(port), } } diff --git a/rule/port.go b/rule/port.go index 281a4c4df3..b6e8abb1cd 100644 --- a/rule/port.go +++ b/rule/port.go @@ -39,7 +39,7 @@ func (p *Port) ShouldResolveIP() bool { } func NewPort(port string, adapter string, isSource bool) (*Port, error) { - _, err := strconv.Atoi(port) + _, err := strconv.ParseUint(port, 10, 16) if err != nil { return nil, errPayload }