mirror of
https://github.com/rapid7/metasploit-payloads
synced 2025-02-16 00:24:29 +01:00
remove do/while(0) exception anti-pattern, fail properly on socket close
This commit is contained in:
parent
e117dd2326
commit
b0fbc4f550
@ -320,21 +320,14 @@ static DWORD packet_receive(Remote *remote, Packet **packet)
|
||||
|
||||
lock_acquire(remote->lock);
|
||||
|
||||
do
|
||||
{
|
||||
dprintf("[TCP PACKET RECEIVE] reading in the header");
|
||||
// Read the packet length
|
||||
while (inHeader)
|
||||
{
|
||||
if ((bytesRead = recv(ctx->fd, ((PUCHAR)&header + headerBytes), sizeof(PacketHeader)-headerBytes, 0)) <= 0)
|
||||
{
|
||||
if (bytesRead < 0)
|
||||
{
|
||||
SetLastError(ERROR_NOT_FOUND);
|
||||
}
|
||||
|
||||
dprintf("[TCP] Socket error");
|
||||
break;
|
||||
goto out;
|
||||
}
|
||||
|
||||
headerBytes += bytesRead;
|
||||
@ -350,7 +343,7 @@ static DWORD packet_receive(Remote *remote, Packet **packet)
|
||||
if (headerBytes != sizeof(PacketHeader))
|
||||
{
|
||||
dprintf("[TCP] we didn't get enough header bytes");
|
||||
break;
|
||||
goto out;
|
||||
}
|
||||
|
||||
dprintf("[TCP] the XOR key is: %02x%02x%02x%02x", header.xor_key[0], header.xor_key[1], header.xor_key[2], header.xor_key[3]);
|
||||
@ -394,7 +387,7 @@ static DWORD packet_receive(Remote *remote, Packet **packet)
|
||||
// did something go wrong.
|
||||
if (bytesToRead > 0)
|
||||
{
|
||||
break;
|
||||
goto out;
|
||||
}
|
||||
|
||||
// indicate success, but don't return a packet for processing
|
||||
@ -424,7 +417,7 @@ static DWORD packet_receive(Remote *remote, Packet **packet)
|
||||
{
|
||||
dprintf("[TCP] Failed to create the packet buffer");
|
||||
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
|
||||
break;
|
||||
goto out;
|
||||
}
|
||||
dprintf("[TCP] Allocated packet buffer at %p", packetBuffer);
|
||||
|
||||
@ -448,8 +441,7 @@ static DWORD packet_receive(Remote *remote, Packet **packet)
|
||||
{
|
||||
SetLastError(ERROR_NOT_FOUND);
|
||||
}
|
||||
|
||||
break;
|
||||
goto out;
|
||||
}
|
||||
|
||||
payloadBytesLeft -= bytesRead;
|
||||
@ -459,7 +451,7 @@ static DWORD packet_receive(Remote *remote, Packet **packet)
|
||||
if (payloadBytesLeft)
|
||||
{
|
||||
dprintf("[TCP] Failed to get all the payload bytes");
|
||||
break;
|
||||
goto out;
|
||||
}
|
||||
|
||||
#ifdef DEBUGTRACE
|
||||
@ -492,8 +484,7 @@ static DWORD packet_receive(Remote *remote, Packet **packet)
|
||||
}
|
||||
}
|
||||
|
||||
} while (0);
|
||||
|
||||
out:
|
||||
res = GetLastError();
|
||||
|
||||
dprintf("[TCP] Freeing stuff up");
|
||||
|
Loading…
Reference in New Issue
Block a user