Skip to content
This repository has been archived by the owner on Nov 14, 2024. It is now read-only.

Commit

Permalink
[nrf noup] zephyr: Fix infinite loop in select
Browse files Browse the repository at this point in the history
fixup! [nrf noup] zephyr: Add support for WPA CLI zephyr

In case of low-memory conditions e.g., in stress tests, the allocation
failure causes the callback to skip recv, there by leaving data on the
socket and causing select to trigger the callback in an infinite loop.

This infinite loop causes threads starvation as WPA supplicant thread
runs at a higher priority, and is manifested as shell freeze.

Fix this by discarding the data on socket in case of memory allocation
failure.

Fixes SHEL-1967.

Signed-off-by: Chaitanya Tata <Chaitanya.Tata@nordicsemi.no>
  • Loading branch information
krish2718 committed Jan 4, 2024
1 parent 42c77f9 commit 8422392
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion wpa_supplicant/ctrl_iface_zephyr.c
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,20 @@ static void wpa_supplicant_ctrl_iface_receive(int sock, void *eloop_ctx,
size_t reply_len = 0;

buf = os_zalloc(CTRL_IFACE_MAX_LEN + 1);
if (!buf)
if (!buf) {
/* Do a dummy read to drain the data from the socket */
static unsigned char dummy[512];

/* This is expected in OOM conditions, so, do not spam the log */
wpa_printf(MSG_DEBUG, "Failed to allocate memory for ctrl_iface receive buffer");

do {
res = recv(sock, dummy, sizeof(dummy),
MSG_TRUNC | MSG_DONTWAIT);
} while (res > 0);
return;
}

res = recv(sock, buf, CTRL_IFACE_MAX_LEN, 0);
if (res < 0) {
wpa_printf(MSG_ERROR, "recvfrom(ctrl_iface): %s",
Expand Down

0 comments on commit 8422392

Please sign in to comment.