From: Francis Dupont Date: Wed, 10 Apr 2019 22:38:55 +0000 (+0200) Subject: [564-customer-request-relax-constraints-on-allowable-option-types-to-permit-option... X-Git-Tag: Kea-1.6.0-beta~231^2~3 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a4b0aa516f27efaa33db58a2f69cbb207b74c9b8;p=thirdparty%2Fkea.git [564-customer-request-relax-constraints-on-allowable-option-types-to-permit-option-type-0-and-255] Moved checks to parsers - still some new tests to add --- diff --git a/src/bin/dhcp4/tests/config_parser_unittest.cc b/src/bin/dhcp4/tests/config_parser_unittest.cc index 7c035595bb..d492e43fb0 100644 --- a/src/bin/dhcp4/tests/config_parser_unittest.cc +++ b/src/bin/dhcp4/tests/config_parser_unittest.cc @@ -3351,7 +3351,7 @@ TEST_F(Dhcp4ParserTest, optionCodeNonUint8) { } // Verify that zero option code is rejected in the configuration. -TEST_F(Dhcp4ParserTest, DISABLED_optionCodeZero) { +TEST_F(Dhcp4ParserTest, optionCodeZero) { // Option code 0 is reserved and should not be accepted // by configuration parser. testInvalidOptionParam("0", "code"); diff --git a/src/bin/dhcp6/tests/config_parser_unittest.cc b/src/bin/dhcp6/tests/config_parser_unittest.cc index 5458e4f41b..64e1c95f26 100644 --- a/src/bin/dhcp6/tests/config_parser_unittest.cc +++ b/src/bin/dhcp6/tests/config_parser_unittest.cc @@ -3555,7 +3555,7 @@ TEST_F(Dhcp6ParserTest, optionCodeHighNonUint16) { } // Verify that zero option code is rejected in the configuration. -TEST_F(Dhcp6ParserTest, DISABLED_optionCodeZero) { +TEST_F(Dhcp6ParserTest, optionCodeZero) { // Option code 0 is reserved and should not be accepted // by configuration parser. testInvalidOptionParam("0", "code"); diff --git a/src/lib/dhcpsrv/parsers/dhcp_parsers.cc b/src/lib/dhcpsrv/parsers/dhcp_parsers.cc index d1c061d962..79af4c879b 100644 --- a/src/lib/dhcpsrv/parsers/dhcp_parsers.cc +++ b/src/lib/dhcpsrv/parsers/dhcp_parsers.cc @@ -6,6 +6,7 @@ #include #include +#include #include #include #include @@ -157,6 +158,29 @@ OptionDefParser::parse(ConstElementPtr option_def) { << getPosition("space", option_def) << ")"); } + // Protect against definition of options 0 (PAD) or 255 (END) + // in (and only in) the dhcp4 space. + if (space == DHCP4_OPTION_SPACE) { + if (code == DHO_PAD) { + isc_throw(DhcpConfigError, "invalid option code '0': " + << "reserved for PAD (" + << getPosition("code", option_def) << ")"); + } else if (code == DHO_END) { + isc_throw(DhcpConfigError, "invalid option code '255': " + << "reserved for END (" + << getPosition("code", option_def) << ")"); + } + } + + // For dhcp6 space the value 0 is reserved. + if (space == DHCP6_OPTION_SPACE) { + if (code == 0) { + isc_throw(DhcpConfigError, "invalid option code '0': " + << "reserved value (" + << getPosition("code", option_def) << ")"); + } + } + // Create option definition. OptionDefinitionPtr def; // We need to check if user has set encapsulated option space diff --git a/src/lib/dhcpsrv/parsers/option_data_parser.cc b/src/lib/dhcpsrv/parsers/option_data_parser.cc index 523ff3560d..93d01dce1b 100644 --- a/src/lib/dhcpsrv/parsers/option_data_parser.cc +++ b/src/lib/dhcpsrv/parsers/option_data_parser.cc @@ -7,6 +7,7 @@ #include #include +#include #include #include #include @@ -302,7 +303,6 @@ OptionDataParser::createOption(ConstElementPtr option_data) { } } - OptionPtr option; OptionDescriptor desc(false); if (!def) { @@ -350,6 +350,29 @@ OptionDataParser::createOption(ConstElementPtr option_data) { } } + // Check PAD and END in (and only in) dhcp4 space. + if (space_param == DHCP4_OPTION_SPACE) { + if (desc.option_->getType() == DHO_PAD) { + isc_throw(DhcpConfigError, "invalid option code '0': " + << "reserved for PAD (" + << option_data->getPosition() << ")"); + } else if (desc.option_->getType() == DHO_END) { + isc_throw(DhcpConfigError, "invalid option code '255': " + << "reserved for END (" + << option_data->getPosition() << ")"); + } + } + + // For dhcp6 space the value 0 is reserved. + if (space_param == DHCP6_OPTION_SPACE) { + if (desc.option_->getType() == 0) { + isc_throw(DhcpConfigError, "invalid option code '0': " + << "reserved value (" + << option_data->getPosition() << ")"); + } + } + + // Add user context if (user_context) { desc.setContext(user_context);