Validate packet size before sending/receiving

This commit is contained in:
Marc André Tanner 2015-02-17 00:20:38 +01:00
parent eef3b654d9
commit bd3dcba548
1 changed files with 4 additions and 0 deletions

View File

@ -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)