mirror of
https://github.com/WiiLink24/wfc-server.git
synced 2026-08-27 11:04:19 -05:00
Merge pull request #82 from ppebb/length-checks
Add length checks to natneg handleReport and qr2 messages
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user