]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[4106] Throw exception from IPC for out of range port.
authorMarcin Siodelski <marcin@isc.org>
Mon, 9 Nov 2015 14:15:04 +0000 (15:15 +0100)
committerMarcin Siodelski <marcin@isc.org>
Mon, 9 Nov 2015 14:15:04 +0000 (15:15 +0100)
src/bin/dhcp4/dhcp4_dhcp4o6_ipc.cc
src/bin/dhcp6/dhcp6_dhcp4o6_ipc.cc
src/lib/dhcpsrv/dhcp4o6_ipc.cc
src/lib/dhcpsrv/tests/dhcp4o6_ipc_unittest.cc

index 8ac834f1d631159b64be9b1226d5e4936e7c4d0b..3db23d7e4cfb0fe14416587bd538ac58c2df3819 100644 (file)
@@ -37,9 +37,6 @@ void Dhcp4o6Ipc::open() {
         Dhcp4o6IpcBase::close();
         return;
     }
-    if (port > 65534) {
-        isc_throw(OutOfRange, "DHCP4o6 port " << port);
-    }
 
     int old_fd = socket_fd_;
     socket_fd_ = Dhcp4o6IpcBase::open(static_cast<uint16_t>(port), ENDPOINT_TYPE_V4);
index 00b99a9d9ed79bc6410c906ac00a6974d1bac0d3..2e54ed304213498a96011237dd7c3183e1a6e172 100644 (file)
@@ -37,9 +37,6 @@ void Dhcp4o6Ipc::open() {
         Dhcp4o6IpcBase::close();
         return;
     }
-    if (port > 65534) {
-        isc_throw(OutOfRange, "DHCP4o6 port " << port);
-    }
 
     int old_fd = socket_fd_;
     socket_fd_ = Dhcp4o6IpcBase::open(static_cast<uint16_t>(port), ENDPOINT_TYPE_V6);
index 0a3b6c3aa64ba306400097427a6f4492b05aa710..4e25d1664347fb677c38c5291d983b74e1273077 100644 (file)
@@ -40,6 +40,12 @@ Dhcp4o6IpcBase::~Dhcp4o6IpcBase() {
 }
 
 int Dhcp4o6IpcBase::open(const uint16_t port, const EndpointType& endpoint_type) {
+    // Check if the port value is correct.
+    if (port > 65534) {
+        isc_throw(Dhcp4o6IpcError, "specified port " << port << " is out of"
+                  " range. The port value must not be greater than 65534 ");
+    }
+
     if (port == port_) {
         // No change: nothing to do
         return (socket_fd_);
index 7b53e5ed729840d9ae0bdc0778c7e18e78266a81..bb7cd3152ce77785ed2e06ec38dda67d5b18efd1 100644 (file)
@@ -531,6 +531,19 @@ TEST_F(Dhcp4o6IpcBaseTest, openError) {
     EXPECT_EQ(TEST_PORT + 10, ipc.getPort());
 }
 
+// This test verifies that the IPC returns an error when trying to bind
+// to the out of range port.
+TEST_F(Dhcp4o6IpcBaseTest, invalidPortError4) {
+    TestIpc ipc(65535, TestIpc::ENDPOINT_TYPE_V4);
+    EXPECT_THROW(ipc.open(), Dhcp4o6IpcError);
+}
+
+// This test verifies that the IPC returns an error when trying to bind
+// to the out of range port.
+TEST_F(Dhcp4o6IpcBaseTest, invalidPortError6) {
+    TestIpc ipc(65535, TestIpc::ENDPOINT_TYPE_V6);
+    EXPECT_THROW(ipc.open(), Dhcp4o6IpcError);
+}
 
 // This test verifies that receiving packet over the IPC fails when there
 // is no vendor option present.