ethernet_interface: Validate gateway IPs
We don't want to allow loopback, network id, or multicast spaces to be
used for the gateway.
Change-Id: I1ff762268321f8c0dacb760611cce8383d880997
Signed-off-by: William A. Kennington III <wak@google.com>
diff --git a/src/ethernet_interface.cpp b/src/ethernet_interface.cpp
index e7a2c29..3374c6f 100644
--- a/src/ethernet_interface.cpp
+++ b/src/ethernet_interface.cpp
@@ -71,6 +71,12 @@
return ret;
}
+template <typename Addr>
+static bool validIntfIP(Addr a) noexcept
+{
+ return a.isUnicast() && !a.isLoopback();
+}
+
EthernetInterface::EthernetInterface(stdplus::PinnedRef<sdbusplus::bus_t> bus,
stdplus::PinnedRef<Manager> manager,
const AllIntfInfo& info,
@@ -826,6 +832,10 @@
gw.clear();
return;
}
+ if (!validIntfIP(ip))
+ {
+ throw std::invalid_argument("Invalid unicast");
+ }
gw = stdplus::toStr(ip);
}
catch (const std::exception& e)