From b47baaa14b09d23961cf9e83fb8033bc3c822a50 Mon Sep 17 00:00:00 2001 From: Roy Marples Date: Wed, 24 Oct 2012 12:13:55 +0000 Subject: [PATCH] More fixes to validation lengths. --- dhcp.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/dhcp.c b/dhcp.c index 25431ff6..b1b66740 100644 --- a/dhcp.c +++ b/dhcp.c @@ -234,8 +234,11 @@ validate_length(uint8_t option, int dl, int *type) opt->type & (STRING | RFC3442 | RFC5969)) return dl; - if (opt->type & IPV4 && opt->type & ARRAY) - return (dl % sizeof(uint32_t) == 0 ? 0 : -1); + if (opt->type & IPV4 && opt->type & ARRAY) { + if (dl < (int)sizeof(uint32_t)) + return -1; + return dl - (dl % sizeof(uint32_t)); + } sz = 0; if (opt->type & (UINT32 | IPV4)) @@ -247,7 +250,7 @@ validate_length(uint8_t option, int dl, int *type) /* If we don't know the size, assume it's valid */ if (sz == 0) return dl; - return sz; + return (sz < dl ? -1 : sz); } /* unknown option, so let it pass */ -- 2.47.3