mirror of https://github.com/martanne/abduco
Validate packet size before sending/receiving
This commit is contained in:
parent
eef3b654d9
commit
bd3dcba548
4
abduco.c
4
abduco.c
|
|
@ -173,6 +173,8 @@ static ssize_t read_all(int fd, char *buf, size_t len) {
|
|||
|
||||
static bool send_packet(int socket, Packet *pkt) {
|
||||
size_t size = packet_size(pkt);
|
||||
if (size > sizeof(*pkt))
|
||||
return false;
|
||||
return write_all(socket, (char *)pkt, size) == size;
|
||||
}
|
||||
|
||||
|
|
@ -180,6 +182,8 @@ static bool recv_packet(int socket, Packet *pkt) {
|
|||
ssize_t len = read_all(socket, (char*)pkt, packet_header_size());
|
||||
if (len <= 0 || len != packet_header_size())
|
||||
return false;
|
||||
if (len > sizeof(pkt->u.msg))
|
||||
return false;
|
||||
if (pkt->len > 0) {
|
||||
len = read_all(socket, pkt->u.msg, pkt->len);
|
||||
if (len <= 0 || len != pkt->len)
|
||||
|
|
|
|||
Loading…
Reference in New Issue