Update golangci-lint configuration

This commit is contained in:
世界 2024-08-27 11:34:24 +08:00
parent caa7813f48
commit b2aa8a079f
No known key found for this signature in database
GPG key ID: CD109927C34A63C4
4 changed files with 21 additions and 10 deletions

View file

@ -5,6 +5,8 @@ linters:
- govet - govet
- gci - gci
- staticcheck - staticcheck
- paralleltest
- ineffassign
linters-settings: linters-settings:
gci: gci:
@ -14,4 +16,9 @@ linters-settings:
- prefix(github.com/sagernet/) - prefix(github.com/sagernet/)
- default - default
staticcheck: staticcheck:
go: '1.20' checks:
- all
- -SA1003
run:
go: "1.23"

View file

@ -20,7 +20,6 @@ import (
E "github.com/sagernet/sing/common/exceptions" 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/rw"
) )
var udpMessagePool = sync.Pool{ var udpMessagePool = sync.Pool{
@ -404,10 +403,12 @@ func decodeUDPMessage(message *udpMessage, data []byte) error {
if err != nil { if err != nil {
return err return err
} }
message.host, err = rw.ReadString(reader, int(hostLen)) hostBytes := make([]byte, hostLen)
_, err = io.ReadFull(reader, hostBytes)
if err != nil { if err != nil {
return err return err
} }
message.host = string(hostBytes)
err = binary.Read(reader, binary.BigEndian, &message.port) err = binary.Read(reader, binary.BigEndian, &message.port)
if err != nil { if err != nil {
return err return err

View file

@ -9,7 +9,6 @@ import (
"github.com/sagernet/sing/common" "github.com/sagernet/sing/common"
"github.com/sagernet/sing/common/buf" "github.com/sagernet/sing/common/buf"
E "github.com/sagernet/sing/common/exceptions" E "github.com/sagernet/sing/common/exceptions"
"github.com/sagernet/sing/common/rw"
) )
const ( const (
@ -81,10 +80,12 @@ func ReadClientHello(reader io.Reader) (*ClientHello, error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
clientHello.Auth, err = rw.ReadString(reader, int(authLen)) authBytes := make([]byte, authLen)
_, err = io.ReadFull(reader, authBytes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
clientHello.Auth = string(authBytes)
return &clientHello, nil return &clientHello, nil
} }

View file

@ -10,7 +10,6 @@ import (
"github.com/sagernet/sing/common" "github.com/sagernet/sing/common"
"github.com/sagernet/sing/common/buf" "github.com/sagernet/sing/common/buf"
E "github.com/sagernet/sing/common/exceptions" E "github.com/sagernet/sing/common/exceptions"
"github.com/sagernet/sing/common/rw"
) )
const ( const (
@ -107,10 +106,12 @@ func ReadTCPResponse(r io.Reader) (ok bool, message string, err error) {
if messageLen > MaxMessageLength { if messageLen > MaxMessageLength {
return false, "", E.New("invalid message length") 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 { if err != nil {
return return
} }
message = string(messageBytes)
paddingLen, err := quicvarint.Read(bReader) paddingLen, err := quicvarint.Read(bReader)
if err != nil { if err != nil {
return return
@ -227,11 +228,12 @@ func ReadVString(reader io.Reader) (string, error) {
if length > MaxAddressLength { if length > MaxAddressLength {
return "", E.New("invalid address length") 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 { if err != nil {
return "", err return "", err
} }
return string(value), nil return string(stringBytes), nil
} }
func WriteVString(writer io.Writer, value string) error { func WriteVString(writer io.Writer, value string) error {
@ -239,7 +241,7 @@ func WriteVString(writer io.Writer, value string) error {
if err != nil { if err != nil {
return err return err
} }
return rw.WriteString(writer, value) return common.Error(writer.Write([]byte(value)))
} }
func WriteUVariant(writer io.Writer, value uint64) error { func WriteUVariant(writer io.Writer, value uint64) error {