diff --git a/.golangci.yml b/.golangci.yml index 4133a1d..fb42693 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -5,6 +5,8 @@ linters: - govet - gci - staticcheck + - paralleltest + - ineffassign linters-settings: gci: @@ -14,4 +16,9 @@ linters-settings: - prefix(github.com/sagernet/) - default staticcheck: - go: '1.20' + checks: + - all + - -SA1003 + +run: + go: "1.23" \ No newline at end of file diff --git a/hysteria/packet.go b/hysteria/packet.go index 54ee52c..e359615 100644 --- a/hysteria/packet.go +++ b/hysteria/packet.go @@ -20,7 +20,6 @@ import ( E "github.com/sagernet/sing/common/exceptions" M "github.com/sagernet/sing/common/metadata" N "github.com/sagernet/sing/common/network" - "github.com/sagernet/sing/common/rw" ) var udpMessagePool = sync.Pool{ @@ -404,10 +403,12 @@ func decodeUDPMessage(message *udpMessage, data []byte) error { if err != nil { return err } - message.host, err = rw.ReadString(reader, int(hostLen)) + hostBytes := make([]byte, hostLen) + _, err = io.ReadFull(reader, hostBytes) if err != nil { return err } + message.host = string(hostBytes) err = binary.Read(reader, binary.BigEndian, &message.port) if err != nil { return err diff --git a/hysteria/protocol.go b/hysteria/protocol.go index c0243df..9174cc7 100644 --- a/hysteria/protocol.go +++ b/hysteria/protocol.go @@ -9,7 +9,6 @@ import ( "github.com/sagernet/sing/common" "github.com/sagernet/sing/common/buf" E "github.com/sagernet/sing/common/exceptions" - "github.com/sagernet/sing/common/rw" ) const ( @@ -81,10 +80,12 @@ func ReadClientHello(reader io.Reader) (*ClientHello, error) { if err != nil { return nil, err } - clientHello.Auth, err = rw.ReadString(reader, int(authLen)) + authBytes := make([]byte, authLen) + _, err = io.ReadFull(reader, authBytes) if err != nil { return nil, err } + clientHello.Auth = string(authBytes) return &clientHello, nil } diff --git a/hysteria2/internal/protocol/proxy.go b/hysteria2/internal/protocol/proxy.go index f76265b..3b0c2f1 100644 --- a/hysteria2/internal/protocol/proxy.go +++ b/hysteria2/internal/protocol/proxy.go @@ -10,7 +10,6 @@ import ( "github.com/sagernet/sing/common" "github.com/sagernet/sing/common/buf" E "github.com/sagernet/sing/common/exceptions" - "github.com/sagernet/sing/common/rw" ) const ( @@ -107,10 +106,12 @@ func ReadTCPResponse(r io.Reader) (ok bool, message string, err error) { if messageLen > MaxMessageLength { return false, "", E.New("invalid message length") } - message, err = rw.ReadString(r, int(messageLen)) + messageBytes := make([]byte, messageLen) + _, err = io.ReadFull(r, messageBytes) if err != nil { return } + message = string(messageBytes) paddingLen, err := quicvarint.Read(bReader) if err != nil { return @@ -227,11 +228,12 @@ func ReadVString(reader io.Reader) (string, error) { if length > MaxAddressLength { return "", E.New("invalid address length") } - value, err := rw.ReadBytes(reader, int(length)) + stringBytes := make([]byte, length) + _, err = io.ReadFull(reader, stringBytes) if err != nil { return "", err } - return string(value), nil + return string(stringBytes), nil } func WriteVString(writer io.Writer, value string) error { @@ -239,7 +241,7 @@ func WriteVString(writer io.Writer, value string) error { if err != nil { return err } - return rw.WriteString(writer, value) + return common.Error(writer.Write([]byte(value))) } func WriteUVariant(writer io.Writer, value uint64) error {