Skip to content

Commit

Permalink
Address PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
jakule committed Feb 24, 2022
1 parent 2bd8b09 commit c69479f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 14 deletions.
8 changes: 6 additions & 2 deletions lib/srv/db/sqlserver/protocol/fuzz_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ package protocol
import (
"bytes"
"testing"

"github.com/stretchr/testify/require"
)

func FuzzMSSQLLogin(f *testing.F) {
Expand All @@ -44,7 +46,9 @@ func FuzzMSSQLLogin(f *testing.F) {

f.Fuzz(func(t *testing.T, packet []byte) {
reader := bytes.NewReader(packet)
// no assertion, check for panic
ReadLogin7Packet(reader)

require.NotPanics(t, func() {
_, _ = ReadLogin7Packet(reader)
})
})
}
16 changes: 4 additions & 12 deletions lib/srv/db/sqlserver/protocol/login7.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,17 +141,13 @@ func ReadLogin7Packet(r io.Reader) (*Login7Packet, error) {
}, nil
}

// errInvalidPackage is returned when Login7 package contains invalid data.
var errInvalidPackage = trace.Errorf("invalid login7 packet")
// errInvalidPacket is returned when Login7 package contains invalid data.
var errInvalidPacket = trace.Errorf("invalid login7 packet")

// readUsername reads username from login7 package.
func readUsername(pkt *Packet, header Login7Header) (string, error) {
if len(pkt.Data) < int(header.IbUserName)+int(header.CchUserName)*2 {
return "", errInvalidPackage
}

if len(pkt.Data) <= int(header.IbUserName) {
return "", errInvalidPackage
return "", errInvalidPacket
}

// Decode username and database from the packet. Offset/length are counted
Expand All @@ -167,11 +163,7 @@ func readUsername(pkt *Packet, header Login7Header) (string, error) {
// readDatabase reads database name from login7 package.
func readDatabase(pkt *Packet, header Login7Header) (string, error) {
if len(pkt.Data) < int(header.IbDatabase)+int(header.CchDatabase)*2 {
return "", errInvalidPackage
}

if len(pkt.Data) < int(header.IbDatabase) {
return "", errInvalidPackage
return "", errInvalidPacket
}

database, err := mssql.ParseUCS2String(
Expand Down

0 comments on commit c69479f

Please sign in to comment.