Skip to content

Commit f4408c0

Browse files
rluboskartben
authored andcommitted
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: Robert Lubos <robert.lubos@nordicsemi.no>
1 parent c4ff1db commit f4408c0

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

subsys/net/lib/dhcpv4/dhcpv4.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1739,8 +1739,11 @@ const char *net_dhcpv4_msg_type_name(enum net_dhcpv4_msg_type msg_type)
17391739
"inform"
17401740
};
17411741

1742-
__ASSERT_NO_MSG(msg_type >= 1 && msg_type <= sizeof(name));
1743-
return name[msg_type - 1];
1742+
if (msg_type >= 1 && msg_type <= sizeof(name)) {
1743+
return name[msg_type - 1];
1744+
}
1745+
1746+
return "invalid";
17441747
}
17451748

17461749
static void dhcpv4_start_internal(struct net_if *iface, bool first_start)

0 commit comments

Comments
 (0)