Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix FuzzRPCClientPartialLength test (MSSQL Server) #25658

Merged
merged 1 commit into from
May 15, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions lib/srv/db/sqlserver/protocol/fixtures/packets.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ var (
// partially Length-prefixed Bytes request, as described here: https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-tds/3f983fde-0509-485a-8c40-a9fa6679a828
func RPCClientPartiallyLength(length uint64, chunks uint64) []byte {
packet := []byte{
0x03, 0x01, 0x00, 0x00, // Length placeholder
0x03, 0x01,
0x00, 0x00, // Length placeholder
0x00, 0x00, 0x01, 0x00, 0x16, 0x00, 0x00, 0x00,
0x12, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00,
Expand All @@ -104,22 +105,32 @@ func RPCClientPartiallyLength(length uint64, chunks uint64) []byte {
0x00, 0x00, 0x00, 0x00, 0x00, // NVARCHARTYPE flags
}

// NVARCHARTYPE must have even length
if length%2 != 0 {
length += 1
}

packet = binary.LittleEndian.AppendUint64(packet, length)

if length > 0 && chunks > 1 {
chunkSize := length / chunks
rem := length
for rem > 0 {
for i := uint64(0); i < chunks-1; i++ {
packet = binary.LittleEndian.AppendUint32(packet, uint32(chunkSize))
data := make([]byte, chunkSize)
packet = append(packet, data...)
rem -= chunkSize
}

// Last chunk will contain the remaining data.
packet = binary.LittleEndian.AppendUint32(packet, uint32(rem))
data := make([]byte, rem)
packet = append(packet, data...)
}

// PLP_TERMINATOR
packet = append(packet, []byte{0x00, 0x00, 0x00, 0x00}...)

packet[3] = byte(len(packet))
binary.BigEndian.PutUint16(packet[2:], uint16(len(packet)))
return packet
}