Skip to content

Commit

Permalink
Update golangci-lint configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
nekohasekai committed Aug 27, 2024
1 parent caa7813 commit b2aa8a0
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 10 deletions.
9 changes: 8 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ linters:
- govet
- gci
- staticcheck
- paralleltest
- ineffassign

linters-settings:
gci:
Expand All @@ -14,4 +16,9 @@ linters-settings:
- prefix(github.com/sagernet/)
- default
staticcheck:
go: '1.20'
checks:
- all
- -SA1003

run:
go: "1.23"
5 changes: 3 additions & 2 deletions hysteria/packet.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions hysteria/protocol.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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
}

Expand Down
12 changes: 7 additions & 5 deletions hysteria2/internal/protocol/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -227,19 +228,20 @@ 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 {
err := WriteUVariant(writer, uint64(len(value)))
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 {
Expand Down

0 comments on commit b2aa8a0

Please sign in to comment.