mirror of
https://github.com/BeamMP/BeamMP-Launcher.git
synced 2026-06-22 08:31:07 +00:00
enforce expected recv size during event and server info tcp recv, remove unused instance of CheckBytes function
This commit is contained in:
@@ -42,7 +42,7 @@ extern std::string magic;
|
||||
int KillSocket(uint64_t Dead);
|
||||
void UUl(const std::string& R);
|
||||
void UDPSend(std::string Data);
|
||||
bool CheckBytes(int32_t Bytes);
|
||||
bool CheckBytes(int32_t Bytes, int32_t Expected = -1);
|
||||
void GameSend(std::string_view Data);
|
||||
void SendLarge(std::string Data);
|
||||
std::string TCPRcv(uint64_t Sock);
|
||||
|
||||
@@ -145,27 +145,26 @@ void GetServerInfo(std::string Data) {
|
||||
std::vector<char> data(sizeof(Header));
|
||||
int Temp = RecvWaitAll(ISock, data.data(), sizeof(Header));
|
||||
|
||||
auto checkBytes = ([&](const int32_t bytes) -> bool {
|
||||
auto checkBytes = ([&](const int32_t bytes, const int32_t expected = -1) -> bool {
|
||||
if (bytes == 0) {
|
||||
return false;
|
||||
} else if (bytes < 0) {
|
||||
return false;
|
||||
}
|
||||
if (expected != -1 && bytes != expected) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
});
|
||||
|
||||
if (!checkBytes(Temp)) {
|
||||
if (!checkBytes(Temp, sizeof(Header))) {
|
||||
return "";
|
||||
}
|
||||
memcpy(&Header, data.data(), sizeof(Header));
|
||||
|
||||
if (!checkBytes(Temp)) {
|
||||
return "";
|
||||
}
|
||||
|
||||
data.resize(Header, 0);
|
||||
Temp = RecvWaitAll(ISock, data.data(), Header);
|
||||
if (!checkBytes(Temp)) {
|
||||
if (!checkBytes(Temp, Header)) {
|
||||
return "";
|
||||
}
|
||||
return std::string(data.data(), Header);
|
||||
|
||||
@@ -50,17 +50,6 @@ int KillSocket(uint64_t Dead) {
|
||||
return a;
|
||||
}
|
||||
|
||||
bool CheckBytes(uint32_t Bytes) {
|
||||
if (Bytes == 0) {
|
||||
debug("(Proxy) Connection closing");
|
||||
return false;
|
||||
} else if (Bytes < 0) {
|
||||
debug("(Proxy) send failed with error: " + std::to_string(WSAGetLastError()));
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void GameSend(std::string_view Data) {
|
||||
static std::mutex Lock;
|
||||
std::scoped_lock Guard(Lock);
|
||||
|
||||
@@ -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 "";
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user