Set packet length to zero on error case

This commit is contained in:
Marc André Tanner 2015-02-17 22:45:38 +01:00
parent f02c3fc3c0
commit 98ac772a97
1 changed files with 3 additions and 1 deletions

View File

@ -182,8 +182,10 @@ 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 (pkt->len > sizeof(pkt->u.msg))
if (pkt->len > sizeof(pkt->u.msg)) {
pkt->len = 0;
return false;
}
if (pkt->len > 0) {
len = read_all(socket, pkt->u.msg, pkt->len);
if (len <= 0 || len != pkt->len)