Commit f4408c08 authored by Robert Lubos's avatar Robert Lubos Committed by Benjamin Cabé
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>
parent c4ff1dbc
Loading
Loading
Loading
Loading
+4 −1
Changes for subsys/net/lib/dhcpv4/dhcpv4.c: 4 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -1739,10 +1739,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;