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

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[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 <[email protected]>
krish2718 committed Jan 2, 2024
1 parent 42c77f9 commit b0559b7
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion wpa_supplicant/ctrl_iface_zephyr.c
Original file line number Diff line number Diff line change
@@ -126,8 +126,21 @@ 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) {
/* Expect this to fail in stress test cases, so use MSG_DEBUG
* instead of MSG_ERROR.
*/
wpa_printf(MSG_DEBUG, "Failed to allocate memory for ctrl_iface receive buffer");
/* Drain the socket */
res = recv(sock, NULL, 0, MSG_TRUNC);
if (res < 0) {
wpa_printf(MSG_DEBUG, "recvfrom(ctrl_iface): %s",
strerror(errno));
}

return;
}

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

0 comments on commit b0559b7

Please sign in to comment.