diff options
author | Francis Dupont <fdupont@isc.org> | 2019-06-05 19:41:04 +0200 |
---|---|---|
committer | Francis Dupont <fdupont@isc.org> | 2019-07-10 10:01:47 +0200 |
commit | 22bd46804664671aae8e0f6abc9c9acb9b7ad3c4 (patch) | |
tree | 0f294443e14d8958b71284d0c63b59ba695bd707 /src/lib | |
parent | [#716,!412] Added ChangeLog for #716. (diff) | |
download | kea-22bd46804664671aae8e0f6abc9c9acb9b7ad3c4.tar.xz kea-22bd46804664671aae8e0f6abc9c9acb9b7ad3c4.zip |
[576-cb-cmds-empty-value-for-next-server-parameter-is-accepted-which-causes-misconfiguration] Protected getSiaddr against global being empty string
Diffstat (limited to 'src/lib')
-rw-r--r-- | src/lib/dhcpsrv/network.h | 10 | ||||
-rw-r--r-- | src/lib/dhcpsrv/tests/network_unittest.cc | 15 |
2 files changed, 23 insertions, 2 deletions
diff --git a/src/lib/dhcpsrv/network.h b/src/lib/dhcpsrv/network.h index dc5237138c..58b4e6a9a5 100644 --- a/src/lib/dhcpsrv/network.h +++ b/src/lib/dhcpsrv/network.h @@ -8,6 +8,7 @@ #define NETWORK_H #include <asiolink/io_address.h> +#include <asiolink/io_error.h> #include <cc/cfg_to_element.h> #include <cc/data.h> #include <cc/element_value.h> @@ -850,8 +851,13 @@ public: /// @return siaddr value util::Optional<asiolink::IOAddress> getSiaddr(const Inheritance& inheritance = Inheritance::ALL) const { - return (getProperty<Network4>(&Network4::getSiaddr, siaddr_, - inheritance, "next-server")); + // Temporary fix for global next-server being the empty string. + try { + return (getProperty<Network4>(&Network4::getSiaddr, siaddr_, + inheritance, "next-server")); + } catch (asiolink::IOError) { + return (siaddr_); + } } /// @brief Sets server hostname for the network. diff --git a/src/lib/dhcpsrv/tests/network_unittest.cc b/src/lib/dhcpsrv/tests/network_unittest.cc index 478b5c5028..ab74ea8af2 100644 --- a/src/lib/dhcpsrv/tests/network_unittest.cc +++ b/src/lib/dhcpsrv/tests/network_unittest.cc @@ -404,4 +404,19 @@ TEST_F(NetworkTest, getPropertyGlobalNoParentNoChild) { EXPECT_EQ("global_iface", net_child->getIface().get()); } +// Test that getSiaddr() never fails. +TEST_F(NetworkTest, getSiaddrNeverFail) { + TestNetworkPtr net_child(new TestNetwork4()); + + // Set the next-server textual address to the empty string. + // Note that IOAddress("") throws IOError. + globals_->set("next-server", Element::create("")); + + net_child->setFetchGlobalsFn(getFetchGlobalsFn()); + + // Get an IPv4 view of the test network. + auto net4_child = boost::dynamic_pointer_cast<Network4>(net_child); + EXPECT_NO_THROW(net4_child->getSiaddr()); +} + } |