BIND 10 trac2318, updated. 4475bf75419cba6488628a2eb6f3b19fc795ae05 [2318] Do not allow zero and negative option codes.
BIND 10 source code commits
bind10-changes at lists.isc.org
Thu Oct 25 18:05:37 UTC 2012
The branch, trac2318 has been updated
via 4475bf75419cba6488628a2eb6f3b19fc795ae05 (commit)
from 9e5e49a5c857b592cc08ba8e3db6a00c9a7fd179 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit 4475bf75419cba6488628a2eb6f3b19fc795ae05
Author: Marcin Siodelski <marcin at isc.org>
Date: Thu Oct 25 20:05:29 2012 +0200
[2318] Do not allow zero and negative option codes.
-----------------------------------------------------------------------
Summary of changes:
src/bin/dhcp6/config_parser.cc | 39 +++++++++++++++++++++----
src/bin/dhcp6/tests/config_parser_unittest.cc | 5 ----
2 files changed, 34 insertions(+), 10 deletions(-)
-----------------------------------------------------------------------
diff --git a/src/bin/dhcp6/config_parser.cc b/src/bin/dhcp6/config_parser.cc
index 6f3e6a0..490d8c0 100644
--- a/src/bin/dhcp6/config_parser.cc
+++ b/src/bin/dhcp6/config_parser.cc
@@ -1,4 +1,4 @@
-// Copyright (C) 2010 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2012 Internet Systems Consortium, Inc. ("ISC")
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
@@ -154,12 +154,37 @@ public:
///
/// @param value pointer to the content of parsed values
virtual void build(ConstElementPtr value) {
+ bool parse_error = false;
+ // Cast the provided value to int64 value to check.
+ int64_t int64value = 0;
try {
- value_ = boost::lexical_cast<uint32_t>(value->str());
- } catch (const boost::bad_lexical_cast &) {
+ // Parsing the value as a int64 value allows to
+ // check if the provided value is within the range
+ // of uint32_t (is not negative or greater than
+ // maximal uint32_t value.
+ int64value = boost::lexical_cast<int64_t>(value->str());
+ } catch (const boost::bad_lexical_cast&) {
+ parse_error = true;
+ }
+ if (!parse_error) {
+ if ((int64value < 0) ||
+ (int64value > std::numeric_limits<uint32_t>::max())) {
+ parse_error = true;
+ } else {
+ try {
+ value_ = boost::lexical_cast<uint32_t>(value->str());
+ } catch (const boost::bad_lexical_cast &) {
+ parse_error = true;
+ }
+ }
+
+ }
+
+ if (parse_error) {
isc_throw(BadValue, "Failed to parse value " << value->str()
<< " as unsigned 32-bit integer.");
}
+
storage_->insert(pair<string, uint32_t>(param_name_, value_));
}
@@ -541,9 +566,13 @@ private:
void createOption() {
// Option code is held in the uint32_t storage but is supposed to
// be uint16_t value. We need to check that value in the configuration
- // does not exceed range of uint16_t.
+ // does not exceed range of uint16_t and is not zero.
uint32_t option_code = getUint32Param("code");
- if (option_code > std::numeric_limits<uint16_t>::max()) {
+ if (option_code == 0) {
+ isc_throw(Dhcp6ConfigError, "Parser error: value of 'code' must not"
+ << " be equal to zero. Option code '0' is reserved in"
+ << " DHCPv6.");
+ } else if (option_code > std::numeric_limits<uint16_t>::max()) {
isc_throw(Dhcp6ConfigError, "Parser error: value of 'code' must not"
<< " exceed " << std::numeric_limits<uint16_t>::max());
}
diff --git a/src/bin/dhcp6/tests/config_parser_unittest.cc b/src/bin/dhcp6/tests/config_parser_unittest.cc
index 8067dd2..02ca20c 100644
--- a/src/bin/dhcp6/tests/config_parser_unittest.cc
+++ b/src/bin/dhcp6/tests/config_parser_unittest.cc
@@ -434,11 +434,6 @@ TEST_F(Dhcp6ParserTest, optionDataInMultipleSubnets) {
const Subnet::OptionContainer& options1 = subnet1->getOptions();
ASSERT_EQ(1, options1.size());
- for (Subnet::OptionContainer::iterator it = options1.begin();
- it != options1.end(); ++it) {
- std::cout << it->option->getType() << std::endl;
- }
-
// Get the search index. Index #1 is to search using option code.
const Subnet::OptionContainerTypeIndex& idx1 = options1.get<1>();
More information about the bind10-changes
mailing list