Skip to content

Commit 456f275

Browse files
authored
fix STOC_CHAT, CTOS_CHAT handling (#2836)
1 parent 56b65a1 commit 456f275

3 files changed

Lines changed: 10 additions & 15 deletions

File tree

gframe/duelclient.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -775,8 +775,12 @@ void DuelClient::HandleSTOCPacketLan(unsigned char* data, int len) {
775775
break;
776776
}
777777
case STOC_CHAT: {
778+
if (len < 1 + sizeof(uint16_t) + sizeof(uint16_t) * 1)
779+
return;
780+
if (len > 1 + sizeof(uint16_t) + sizeof(uint16_t) * LEN_CHAT_MSG)
781+
return;
778782
const int chat_msg_size = len - 1 - sizeof(uint16_t);
779-
if (!check_msg_size(chat_msg_size))
783+
if (chat_msg_size % sizeof(uint16_t))
780784
return;
781785
uint16_t chat_player_type = buffer_read<uint16_t>(pdata);
782786
uint16_t chat_msg[LEN_CHAT_MSG];

gframe/netserver.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,11 @@ void NetServer::HandleCTOSPacket(DuelPlayer* dp, unsigned char* data, int len) {
206206
case CTOS_CHAT: {
207207
if(!dp->game)
208208
return;
209-
if (len < 1 + (int)sizeof(unsigned char))
209+
if (len < 1 + sizeof(uint16_t) * 1)
210+
return;
211+
if (len > 1 + sizeof(uint16_t) * LEN_CHAT_MSG)
212+
return;
213+
if ((len - 1) % sizeof(uint16_t))
210214
return;
211215
duel_mode->Chat(dp, pdata, len - 1);
212216
break;
@@ -360,8 +364,6 @@ void NetServer::HandleCTOSPacket(DuelPlayer* dp, unsigned char* data, int len) {
360364
}
361365
}
362366
size_t NetServer::CreateChatPacket(unsigned char* src, int src_size, unsigned char* dst, uint16_t dst_player_type) {
363-
if (!check_msg_size(src_size))
364-
return 0;
365367
uint16_t src_msg[LEN_CHAT_MSG];
366368
std::memcpy(src_msg, src, src_size);
367369
const int src_len = src_size / sizeof(uint16_t);

gframe/network.h

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -196,17 +196,6 @@ struct DuelPlayer {
196196
bufferevent* bev{};
197197
};
198198

199-
inline bool check_msg_size(int size) {
200-
// empty string is not allowed
201-
if (size < 2 * sizeof(uint16_t))
202-
return false;
203-
if (size > LEN_CHAT_MSG * sizeof(uint16_t))
204-
return false;
205-
if (size % sizeof(uint16_t) != 0)
206-
return false;
207-
return true;
208-
}
209-
210199
inline unsigned int GetPosition(unsigned char* qbuf, size_t offset) {
211200
unsigned int info = 0;
212201
std::memcpy(&info, qbuf + offset, sizeof info);

0 commit comments

Comments
 (0)