Skip to content

Commit

Permalink
net: lib: dhcpv4: Add check for input parameter of echo_reply_handler
Browse files Browse the repository at this point in the history
For station and internal AP coexist case, station connected to
external AP, ping from station to external AP cause cpu hang.

Internal AP dhcpv4 server register handler echo_reply_handler
on icmp handler by net_icmp_init_ctx for dhcp server snoop
feature. Ping also register handler handle_ipv4_echo_reply on
icmp handler for ping cmd. If no external station connect to
internal AP, input parameter ‘user_data’ of function
echo_reply_handler is NULL. When we trigger ping process,
icmp_call_handlers fetch all handlers from icmp handler
if receive any ICMP packet, so echo_reply_handler be called,
but input parameter is NULL, cause CPU hang.
Add input parameters check to fix this issue.

Signed-off-by: Rex Chen <rex.chen_1@nxp.com>
  • Loading branch information
Rex-Chen-NXP authored and aescolar committed Jun 18, 2024
1 parent 0b71206 commit dcf4291
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion subsys/net/lib/dhcpv4/dhcpv4_server.c
Original file line number Diff line number Diff line change
Expand Up @@ -737,7 +737,7 @@ static int echo_reply_handler(struct net_icmp_ctx *icmp_ctx,
void *user_data)
{
struct dhcpv4_server_ctx *ctx = user_data;
struct dhcpv4_server_probe_ctx *probe_ctx = &ctx->probe_ctx;
struct dhcpv4_server_probe_ctx *probe_ctx;
struct dhcpv4_addr_slot *new_slot = NULL;
struct in_addr peer_addr;

Expand All @@ -748,6 +748,12 @@ static int echo_reply_handler(struct net_icmp_ctx *icmp_ctx,

k_mutex_lock(&server_lock, K_FOREVER);

if (ctx == NULL) {
goto out;
}

probe_ctx = &ctx->probe_ctx;

if (probe_ctx->slot == NULL) {
goto out;
}
Expand Down

0 comments on commit dcf4291

Please sign in to comment.