Commit a147ac9a authored by Robert Lubos's avatar Robert Lubos Committed by Fabio Baltieri
Browse files

net: dhcpv4_server: Improve address pool range validation



Not only check if the address pool belongs to the same subnet as the
server, but also that it does not overlap with the server address -
otherwise the server might end up assigning its own address.

Signed-off-by: default avatarRobert Lubos <robert.lubos@nordicsemi.no>
parent a08604c6
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -1224,6 +1224,13 @@ int net_dhcpv4_server_start(struct net_if *iface, struct in_addr *base_addr)
		return -EINVAL;
	}

	if ((htonl(server_addr->s_addr) >= htonl(base_addr->s_addr)) &&
	    (htonl(server_addr->s_addr) <
	     htonl(base_addr->s_addr) + CONFIG_NET_DHCPV4_SERVER_ADDR_COUNT)) {
		LOG_ERR("Address pool overlaps with server address.");
		return -EINVAL;
	}

	netmask = net_if_ipv4_get_netmask(iface);
	if (net_ipv4_is_addr_unspecified(&netmask)) {
		LOG_ERR("Failed to obtain subnet mask.");