Skip to content

Commit

Permalink
dhcp4: detect invalid length of static routes on parsing
Browse files Browse the repository at this point in the history
Set underflow and do not parse the whole list.
  • Loading branch information
wipawel committed Jul 1, 2015
1 parent 3a77c6d commit 0cbe2f7
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions dhcp4/protocol.c
Expand Up @@ -1352,6 +1352,11 @@ cidr_to_netmask(unsigned int pfxlen)
static int
ni_dhcp4_decode_static_routes(ni_buffer_t *bp, ni_route_array_t *routes)
{
if (ni_buffer_count(bp) % 4) {
bp->underflow = 1;
return -1;
}

while (ni_buffer_count(bp) && !bp->underflow) {
ni_sockaddr_t destination, gateway;
ni_route_t *rp;
Expand All @@ -1367,6 +1372,9 @@ ni_dhcp4_decode_static_routes(ni_buffer_t *bp, ni_route_array_t *routes)
ni_route_array_append(routes, rp);
}

if (bp->underflow)
return -1;

return 0;
}

Expand Down

0 comments on commit 0cbe2f7

Please sign in to comment.