mirror of
https://github.com/OpenFusionProject/OpenFusion.git
synced 2024-11-04 22:40:05 +00:00
added sanity checks for sendPacket()
This commit is contained in:
parent
bf6c5d1b6b
commit
c5efbceca3
@ -76,8 +76,12 @@ bool CNSocket::sendData(uint8_t* data, int size) {
|
||||
|
||||
while (sentBytes < size) {
|
||||
int sent = send(sock, (buffer_t*)(data + sentBytes), size - sentBytes, 0); // no flags defined
|
||||
if (SOCKETERROR(sent))
|
||||
if (SOCKETERROR(sent)) {
|
||||
if (errno == 11)
|
||||
continue; // try again
|
||||
std::cout << "[FATAL] SOCKET ERROR: " << errno << std::endl;
|
||||
return false; // error occured while sending bytes
|
||||
}
|
||||
sentBytes += sent;
|
||||
}
|
||||
|
||||
@ -116,6 +120,11 @@ void CNSocket::kill() {
|
||||
}
|
||||
|
||||
void CNSocket::sendPacket(CNPacketData* pak) {
|
||||
if (!alive) {
|
||||
delete pak;
|
||||
return;
|
||||
}
|
||||
|
||||
int tmpSize = pak->size + sizeof(uint32_t);
|
||||
uint8_t* tmpBuf = (uint8_t*)xmalloc(tmpSize);
|
||||
|
||||
@ -127,10 +136,12 @@ void CNSocket::sendPacket(CNPacketData* pak) {
|
||||
CNSocketEncryption::encryptData((uint8_t*)tmpBuf, (uint8_t*)(&pak->key), tmpSize);
|
||||
|
||||
// send packet size
|
||||
sendData((uint8_t*)&tmpSize, sizeof(uint32_t));
|
||||
if (!sendData((uint8_t*)&tmpSize, sizeof(uint32_t)))
|
||||
kill();
|
||||
|
||||
// send packet data!
|
||||
sendData(tmpBuf, tmpSize);
|
||||
if (alive && !sendData(tmpBuf, tmpSize))
|
||||
kill();
|
||||
|
||||
delete pak;
|
||||
free(tmpBuf); // free tmp buffer
|
||||
|
Loading…
Reference in New Issue
Block a user