Commit 532d11bf authored by Robert Lubos's avatar Robert Lubos Committed by Anas Nashif
Browse files

net: dhcpv4: client: Prevent asserting on malformed message



In case the received DHCP message is malformed and contains invalid
message type, the code responsible for matching message type with a
string would assert. This shouldn't be the case that external conditions
(like receiving malformed packet) trigger asserts in the system.
Therefore modify that code, to return "invalid" string in such case
instead.

Signed-off-by: default avatarRobert Lubos <robert.lubos@nordicsemi.no>
(cherry picked from commit f4408c08)
parent 3ef6fe94
Loading
Loading
Loading
Loading
+5 −2
Original line number Diff line number Diff line
@@ -1652,10 +1652,13 @@ const char *net_dhcpv4_msg_type_name(enum net_dhcpv4_msg_type msg_type)
		"inform"
	};

	__ASSERT_NO_MSG(msg_type >= 1 && msg_type <= sizeof(name));
	if (msg_type >= 1 && msg_type <= sizeof(name)) {
		return name[msg_type - 1];
	}

	return "invalid";
}

static void dhcpv4_start_internal(struct net_if *iface, bool first_start)
{
	uint32_t entropy;