]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[576-cb-cmds-empty-value-for-next-server-parameter-is-accepted-which-causes-misconfig...
authorFrancis Dupont <fdupont@isc.org>
Wed, 5 Jun 2019 17:41:04 +0000 (19:41 +0200)
committerFrancis Dupont <fdupont@isc.org>
Wed, 10 Jul 2019 08:01:47 +0000 (04:01 -0400)
src/lib/dhcpsrv/network.h
src/lib/dhcpsrv/tests/network_unittest.cc

index dc5237138cdd6662b12537b5ed306b3493e5daa1..58b4e6a9a5696bff84742c6809c7d1c7c1d91005 100644 (file)
@@ -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.
index 478b5c50287e6e15c9f4efe76347b3f015face2d..ab74ea8af2aab5e974410d49d1f446c19a744ddc 100644 (file)
@@ -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());
+}
+
 }