Fix packet length validation
This commit is contained in:
parent
545d31a54a
commit
f944f320b9
1 changed files with 5 additions and 2 deletions
7
nmrp.c
7
nmrp.c
|
|
@ -276,10 +276,13 @@ static int pkt_recv(struct ethsock *sock, struct nmrp_pkt *pkt)
|
||||||
|
|
||||||
len = ntohs(pkt->msg.len) + sizeof(pkt->eh);
|
len = ntohs(pkt->msg.len) + sizeof(pkt->eh);
|
||||||
|
|
||||||
if (bytes != len) {
|
if (bytes < len) {
|
||||||
fprintf(stderr, "Unexpected packet length (expected %d, got %d).\n",
|
fprintf(stderr, "Short packet (expected %d, got %d).\n",
|
||||||
(int)len, (int)bytes);
|
(int)len, (int)bytes);
|
||||||
return 1;
|
return 1;
|
||||||
|
} else if (bytes > sizeof(pkt->msg) + sizeof(pkt->eh)) {
|
||||||
|
fprintf(stderr, "Packet size exceeds maximum (got %d).\n",
|
||||||
|
(int)bytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue