From f944f320b90ea58a97090da52b3656dc462690a7 Mon Sep 17 00:00:00 2001 From: "Joseph C. Lehner" Date: Sun, 19 Feb 2017 11:34:01 +0100 Subject: [PATCH] Fix packet length validation --- nmrp.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/nmrp.c b/nmrp.c index 7e2b74b..a6d9e4f 100644 --- a/nmrp.c +++ b/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); - if (bytes != len) { - fprintf(stderr, "Unexpected packet length (expected %d, got %d).\n", + if (bytes < len) { + fprintf(stderr, "Short packet (expected %d, got %d).\n", (int)len, (int)bytes); return 1; + } else if (bytes > sizeof(pkt->msg) + sizeof(pkt->eh)) { + fprintf(stderr, "Packet size exceeds maximum (got %d).\n", + (int)bytes); } return 0; -- 2.25.1