1
mirror of https://github.com/rapid7/metasploit-payloads synced 2025-03-30 22:19:17 +02:00

remove do/while(0) exception anti-pattern

This commit is contained in:
Brent Cook 2017-11-06 08:05:49 -06:00
parent 2dc48bea43
commit 0548a12f3c

@ -340,12 +340,10 @@ static DWORD packet_receive_http(Remote *remote, Packet **packet)
lock_acquire(remote->lock);
do
{
hReq = ctx->create_req(ctx, TRUE, "PACKET RECEIVE");
if (hReq == NULL)
{
break;
goto out;
}
vdprintf("[PACKET RECEIVE HTTP] sending GET");
@ -355,7 +353,7 @@ static DWORD packet_receive_http(Remote *remote, Packet **packet)
{
dprintf("[PACKET RECEIVE HTTP] Failed send_req: %d %d", GetLastError(), WSAGetLastError());
SetLastError(ERROR_NOT_FOUND);
break;
goto out;
}
vdprintf("[PACKET RECEIVE HTTP] Waiting to see the response ...");
@ -363,15 +361,14 @@ static DWORD packet_receive_http(Remote *remote, Packet **packet)
{
vdprintf("[PACKET RECEIVE] Failed receive: %d", GetLastError());
SetLastError(ERROR_NOT_FOUND);
break;
goto out;
}
SetLastError(ctx->validate_response(hReq, ctx));
if (GetLastError() != ERROR_SUCCESS)
{
// something went wrong, so break
break;
goto out;
}
// Read the packet length
@ -384,7 +381,7 @@ static DWORD packet_receive_http(Remote *remote, Packet **packet)
{
dprintf("[PACKET RECEIVE HTTP] Failed HEADER read_response: %d", GetLastError());
SetLastError(ERROR_NOT_FOUND);
break;
goto out;
}
vdprintf("[PACKET RECEIVE NHTTP] Data received: %u bytes", bytesRead);
@ -395,7 +392,7 @@ static DWORD packet_receive_http(Remote *remote, Packet **packet)
if (bytesRead == 0)
{
SetLastError(ERROR_EMPTY);
break;
goto out;
}
headerBytes += bytesRead;
@ -408,16 +405,11 @@ static DWORD packet_receive_http(Remote *remote, Packet **packet)
inHeader = FALSE;
}
if (GetLastError() == ERROR_EMPTY)
{
break;
}
if (headerBytes != sizeof(PacketHeader))
{
dprintf("[PACKET RECEIVE HTTP] headerBytes no valid");
dprintf("[PACKET RECEIVE HTTP] headerBytes not valid");
SetLastError(ERROR_NOT_FOUND);
break;
goto out;
}
dprintf("[PACKET RECEIVE HTTP] decoding header");
@ -427,7 +419,7 @@ static DWORD packet_receive_http(Remote *remote, Packet **packet)
#ifdef DEBUGTRACE
PUCHAR h = (PUCHAR)&header;
vdprintf("[TCP] Packet header: [0x%02X 0x%02X 0x%02X 0x%02X] [0x%02X 0x%02X 0x%02X 0x%02X 0x%02X 0x%02X 0x%02X 0x%02X 0x%02X 0x%02X 0x%02X 0x%02X 0x%02X 0x%02X 0x%02X 0x%02X] [0x%02X 0x%02X 0x%02X 0x%02X] [0x%02X 0x%02X 0x%02X 0x%02X] [0x%02X 0x%02X 0x%02X 0x%02X]",
vdprintf("[HTTP] Packet header: [0x%02X 0x%02X 0x%02X 0x%02X] [0x%02X 0x%02X 0x%02X 0x%02X 0x%02X 0x%02X 0x%02X 0x%02X 0x%02X 0x%02X 0x%02X 0x%02X 0x%02X 0x%02X 0x%02X 0x%02X] [0x%02X 0x%02X 0x%02X 0x%02X] [0x%02X 0x%02X 0x%02X 0x%02X] [0x%02X 0x%02X 0x%02X 0x%02X]",
h[0], h[1], h[2], h[3], h[4], h[5], h[6], h[7], h[8], h[9], h[10], h[11], h[12], h[13], h[14], h[15], h[16], h[17], h[18], h[19], h[20], h[21], h[22], h[23], h[24], h[25], h[26], h[27], h[28], h[29], h[30], h[31]);
#endif
@ -442,7 +434,7 @@ static DWORD packet_receive_http(Remote *remote, Packet **packet)
{
dprintf("[REC HTTP] Failed to create the packet buffer");
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
break;
goto out;
}
dprintf("[REC HTTP] Allocated packet buffer at %p", packetBuffer);
@ -461,14 +453,14 @@ static DWORD packet_receive_http(Remote *remote, Packet **packet)
{
dprintf("[PACKET RECEIVE] Failed BODY read_response: %d", GetLastError());
SetLastError(ERROR_NOT_FOUND);
break;
goto out;
}
if (!bytesRead)
{
vdprintf("[PACKET RECEIVE HTTP] no bytes read, bailing out");
SetLastError(ERROR_NOT_FOUND);
break;
goto out;
}
vdprintf("[PACKET RECEIVE HTTP] bytes read: %u", bytesRead);
@ -478,7 +470,7 @@ static DWORD packet_receive_http(Remote *remote, Packet **packet)
// Didn't finish?
if (payloadBytesLeft)
{
break;
goto out;
}
#ifdef DEBUGTRACE
@ -510,8 +502,8 @@ static DWORD packet_receive_http(Remote *remote, Packet **packet)
dprintf("[HTTP] Session GUIDs don't match, can't find pivot!");
}
}
} while (0);
out:
res = GetLastError();
dprintf("[HTTP] Cleaning up");