From 49c766398d47846bd837f5aa83b8bec930e3cf0e Mon Sep 17 00:00:00 2001 From: Stefano Brivio Date: Thu, 22 Apr 2021 02:30:20 +0200 Subject: dhcpv6: Subtract option length before returning one option dhcpv6_opt() needs to subtract option length _before_ returning, so that callers can conveniently pass the remaining length on subsequent calls. Signed-off-by: Stefano Brivio --- dhcpv6.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/dhcpv6.c b/dhcpv6.c index f0217d0..7f566a5 100644 --- a/dhcpv6.c +++ b/dhcpv6.c @@ -277,10 +277,11 @@ static struct opt_hdr *dhcpv6_opt(struct opt_hdr *o, uint16_t type, size_t *len) if (ntohs(o->l) > *len) return NULL; + *len -= ntohs(o->l) + sizeof(struct opt_hdr); + if (o->t == type) return o; - *len -= ntohs(o->l) + sizeof(struct opt_hdr); o = (struct opt_hdr *)((uint8_t *)(o + 1) + ntohs(o->l)); } -- cgit v1.2.3