Skip to content

Commit c0e6817

Browse files
committed
Properly verify qr2 messages
1 parent 550f70c commit c0e6817

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

qr2/message.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ func SendClientMessage(senderIP string, destSearchID uint64, message []byte) {
5959

6060
// Decode and validate the message
6161
isNatnegPacket := false
62-
if bytes.Equal(message[:2], []byte{0xfd, 0xfc}) {
62+
if len(message) >= 2 && bytes.Equal(message[:2], []byte{0xfd, 0xfc}) {
6363
// Sending natneg cookie
6464
isNatnegPacket = true
6565
if len(message) != 0xA {
@@ -69,7 +69,7 @@ func SendClientMessage(senderIP string, destSearchID uint64, message []byte) {
6969

7070
natnegID := binary.LittleEndian.Uint32(message[0x6:0xA])
7171
moduleName = "QR2/MSG:s" + strconv.FormatUint(uint64(natnegID), 10)
72-
} else if bytes.Equal(message[:4], []byte{0xbb, 0x49, 0xcc, 0x4d}) || bytes.Equal(message[:4], []byte("SBCM")) {
72+
} else if len(message) >= 4 && (bytes.Equal(message[:4], []byte{0xbb, 0x49, 0xcc, 0x4d}) || bytes.Equal(message[:4], []byte("SBCM"))) {
7373
// DWC match command
7474
if len(message) < 0x14 || len(message) > 0x94 {
7575
logging.Error(moduleName, "Received invalid length match command packet")
@@ -219,6 +219,7 @@ func SendClientMessage(senderIP string, destSearchID uint64, message []byte) {
219219
}
220220
} else {
221221
logging.Error(moduleName, "Invalid message:", aurora.Cyan(printHex(message)))
222+
return
222223
}
223224

224225
destSessionID, packetCount, destAddr := processClientMessage(moduleName, sender, receiver, message, isNatnegPacket, matchData)

0 commit comments

Comments
 (0)