2217. [func] fdupont
Extended the lenient-option-parsing compatibility
- flag to ignore DHCPv4 fqdn (81) option with some
- invalid domain names (e.g. beginning with an empty label).
+ flag to ignore DHCPv4 fqdn (81) and DHCPv6 client-fqdn
+ (39) options with some invalid domain names (e.g.
+ beginning with an empty label).
(Gitlab 3289)
2216. [func] tmark
try {
domain_name_.reset(new isc::dns::Name(name_buf, true));
} catch (const Exception&) {
- isc_throw(InvalidOption6FqdnDomainName, "failed to parse "
- "partial domain-name from wire format");
+ if (Option::lenient_parsing_) {
+ isc_throw(SkipThisOptionError, "failed to parse "
+ "partial domain-name from wire format");
+ } else {
+ isc_throw(InvalidOption6FqdnDomainName, "failed to parse "
+ "partial domain-name from wire format");
+ }
}
// Terminating zero was missing, so set the domain-name type
// to partial.
try {
domain_name_.reset(new isc::dns::Name(name_buf, true));
} catch (const Exception&) {
- isc_throw(InvalidOption6FqdnDomainName, "failed to parse "
- "fully qualified domain-name from wire format");
+ if (Option::lenient_parsing_) {
+ isc_throw(SkipThisOptionError, "failed to parse "
+ "fully qualified domain-name from wire format");
+ } else {
+ isc_throw(InvalidOption6FqdnDomainName, "failed to parse "
+ "fully qualified domain-name from wire format");
+ }
}
// Set the domain-type to fully qualified domain name.
domain_name_type_ = Option6ClientFqdn::FULL;
using namespace isc;
using namespace isc::dhcp;
+// RAII device to make sure that lenient parsing flag is reset to false on exit.
+class LenientOptionParsing {
+public:
+ LenientOptionParsing(bool value) {
+ Option::lenient_parsing_ = value;
+ }
+
+ ~LenientOptionParsing() {
+ Option::lenient_parsing_ = false;
+ }
+};
+
// This test verifies that constructor accepts empty partial domain-name but
// does not accept empty fully qualified domain name.
TEST(Option6ClientFqdnTest, constructEmptyName) {
OptionBuffer in_buf(Option6ClientFqdn::FLAG_S);
in_buf.push_back(70);
in_buf.insert(in_buf.end(), 70, 109);
- in_buf.push_back(0);
+ // Don't add a 0 i.e. use a partial name (vs fully qualified).
+ LenientOptionParsing(false);
EXPECT_THROW(Option6ClientFqdn(in_buf.begin(), in_buf.end()),
InvalidOption6FqdnDomainName);
+ Option::lenient_parsing_ = true;
+ EXPECT_THROW(Option6ClientFqdn(in_buf.begin(), in_buf.end()),
+ SkipThisOptionError);
}
// Verify that exception is thrown if the overall length of the domain-name
// Terminate FQDN with a dot.
in_buf.push_back(0);
+ LenientOptionParsing(false);
EXPECT_THROW(Option6ClientFqdn(in_buf.begin(), in_buf.end()),
InvalidOption6FqdnDomainName);
+ Option::lenient_parsing_ = true;
+ EXPECT_THROW(Option6ClientFqdn(in_buf.begin(), in_buf.end()),
+ SkipThisOptionError);
}
// This test verifies that truncated option is rejected.
ASSERT_NO_THROW(Option6ClientFqdn(0, "myhost.example.com"));
// Specify invalid domain name and expect that exception is thrown.
+ // Note in v6 the domain name is always encoded so this is not
+ // covered by lenient-option-parsing.
EXPECT_THROW(Option6ClientFqdn(0, "my...host.example.com"),
InvalidOption6FqdnDomainName);
}