Merge pull request #82 from ppebb/length-checks

Add length checks to natneg handleReport and qr2 messages
This commit is contained in:
Palapeli
2025-06-03 18:58:32 -04:00
committed by GitHub
2 changed files with 9 additions and 3 deletions

View File

@@ -9,7 +9,12 @@ import (
"github.com/logrusorgru/aurora/v3"
)
func (session *NATNEGSession) handleReport(conn net.PacketConn, addr net.Addr, buffer []byte, _ string, version byte) {
func (session *NATNEGSession) handleReport(conn net.PacketConn, addr net.Addr, buffer []byte, _moduleName string, version byte) {
if len(buffer) < 2 {
logging.Error(_moduleName, "Invalid packet size")
return
}
response := createPacketHeader(version, NNReportReply, session.Cookie)
response = append(response, buffer[:9]...)
response[14] = 0

View File

@@ -65,7 +65,7 @@ func SendClientMessage(senderIP string, destSearchID uint64, message []byte) {
// Decode and validate the message
isNatnegPacket := false
if bytes.Equal(message[:2], []byte{0xfd, 0xfc}) {
if len(message) >= 2 && bytes.Equal(message[:2], []byte{0xfd, 0xfc}) {
// Sending natneg cookie
isNatnegPacket = true
if len(message) != 0xA {
@@ -75,7 +75,7 @@ func SendClientMessage(senderIP string, destSearchID uint64, message []byte) {
natnegID := binary.LittleEndian.Uint32(message[0x6:0xA])
moduleName = "QR2/MSG:s" + strconv.FormatUint(uint64(natnegID), 10)
} else if bytes.Equal(message[:4], []byte{0xbb, 0x49, 0xcc, 0x4d}) || bytes.Equal(message[:4], []byte("SBCM")) {
} else if len(message) >= 4 && (bytes.Equal(message[:4], []byte{0xbb, 0x49, 0xcc, 0x4d}) || bytes.Equal(message[:4], []byte("SBCM"))) {
// DWC match command
if len(message) < 0x14 || len(message) > 0x94 {
logging.Error(moduleName, "Received invalid length match command packet")
@@ -228,6 +228,7 @@ func SendClientMessage(senderIP string, destSearchID uint64, message []byte) {
}
} else {
logging.Error(moduleName, "Invalid message:", aurora.Cyan(printHex(message)))
return
}
destSessionID, packetCount, destAddr := processClientMessage(moduleName, sender, receiver, message, isNatnegPacket, matchData)