From: Mukund Sivaraman Date: Tue, 30 Oct 2012 12:18:08 +0000 (+0530) Subject: [master] Check IPv6 mask length X-Git-Tag: trac2487_base~31 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=127e416cb3b2d08b2cd9356ca7c8bd109dbef95d;p=thirdparty%2Fkea.git [master] Check IPv6 mask length --- diff --git a/src/lib/dhcp/addr_utilities.cc b/src/lib/dhcp/addr_utilities.cc index de1e8b46a2..db35ca61f3 100644 --- a/src/lib/dhcp/addr_utilities.cc +++ b/src/lib/dhcp/addr_utilities.cc @@ -45,9 +45,13 @@ const uint8_t bitMask6[]= { 0, 0x80, 0xc0, 0xe0, 0xf0, 0xf8, 0xfc, 0xfe, 0xff }; /// @param len prefix length isc::asiolink::IOAddress firstAddrInPrefix6(const isc::asiolink::IOAddress& prefix, uint8_t len) { - uint8_t packed[V6ADDRESS_LEN]; + if (len > 128) { + isc_throw(isc::BadValue, + "Too large netmask. 0..128 is allowed in IPv6"); + } + // First we copy the whole address as 16 bytes. memcpy(packed, prefix.getAddress().to_v6().to_bytes().data(), 16); @@ -104,7 +108,7 @@ isc::asiolink::IOAddress firstAddrInPrefix4(const isc::asiolink::IOAddress& pref isc::asiolink::IOAddress lastAddrInPrefix4(const isc::asiolink::IOAddress& prefix, uint8_t len) { uint32_t addr = prefix; - if (len>32) { + if (len > 32) { isc_throw(isc::BadValue, "Too large netmask. 0..32 is allowed in IPv4"); } @@ -123,6 +127,11 @@ isc::asiolink::IOAddress lastAddrInPrefix6(const isc::asiolink::IOAddress& prefi uint8_t packed[V6ADDRESS_LEN]; + if (len > 128) { + isc_throw(isc::BadValue, + "Too large netmask. 0..128 is allowed in IPv6"); + } + // First we copy the whole address as 16 bytes. memcpy(packed, prefix.getAddress().to_v6().to_bytes().data(), 16);