enforce expected recv size during event and server info tcp recv, remove unused instance of CheckBytes function

This commit is contained in:
Katharine Chui
2026-05-11 11:08:15 +02:00
parent 23760da53b
commit 30639abb88
4 changed files with 16 additions and 23 deletions
+9 -4
View File
@@ -28,9 +28,9 @@ int LastPort;
std::string LastIP;
SOCKET TCPSock = -1;
bool CheckBytes(int32_t Bytes) {
bool CheckBytes(int32_t Bytes, int32_t Expected) {
if (Bytes == 0) {
debug("(TCP) Connection closing... CheckBytes(16)");
debug("(TCP) Connection closing...");
Terminate = true;
return false;
} else if (Bytes < 0) {
@@ -39,6 +39,11 @@ bool CheckBytes(int32_t Bytes) {
Terminate = true;
return false;
}
if (Expected != -1 && Bytes != Expected) {
debug(std::format("(TCP) Short recv detected, expected {} bytes, got {} bytes", Expected, Bytes));
Terminate = true;
return false;
}
return true;
}
void UUl(const std::string& R) {
@@ -103,7 +108,7 @@ std::string TCPRcv(SOCKET Sock) {
int Temp;
std::vector<char> Data(sizeof(Header));
Temp = RecvWaitAll(Sock, Data.data(), sizeof(Header));
if (!CheckBytes(Temp)) {
if (!CheckBytes(Temp, sizeof(Header))) {
UUl("Socket Closed Code 3");
return "";
}
@@ -116,7 +121,7 @@ std::string TCPRcv(SOCKET Sock) {
Data.resize(Header, 0);
Temp = RecvWaitAll(Sock, Data.data(), Header);
if (!CheckBytes(Temp)) {
if (!CheckBytes(Temp, Header)) {
UUl("Socket Closed Code 5");
return "";
}