From 37c83a4c92288372367d91afe877e54de5785e2b Mon Sep 17 00:00:00 2001 From: Chaitanya Tata Date: Thu, 8 Feb 2024 18:14:30 +0530 Subject: [PATCH] [nrf noup] zephyr: Don't use heap for WPA cli Relying on heap during OOM is bad, esp. for critical module like WPA supplicant, this can break the Wi-Fi. As the WPA supplicant stack is large enough and this buffer is free immediately after use, just use the stack. Fixes SHEL-2283. Signed-off-by: Chaitanya Tata --- wpa_supplicant/wpa_cli_cmds.c | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/wpa_supplicant/wpa_cli_cmds.c b/wpa_supplicant/wpa_cli_cmds.c index 98c254a9b..c71dfe709 100644 --- a/wpa_supplicant/wpa_cli_cmds.c +++ b/wpa_supplicant/wpa_cli_cmds.c @@ -39,7 +39,7 @@ static DEFINE_DL_LIST(stations); /* struct cli_txt_entry */ static int wpa_cli_cmd(struct wpa_ctrl *ctrl, const char *cmd, int min_args, int argc, char *argv[]) { - char * buf = NULL; + char buf[CMD_BUF_LEN] = {0}; int ret = 0; bool interactive = 0; @@ -58,13 +58,7 @@ static int wpa_cli_cmd(struct wpa_ctrl *ctrl, const char *cmd, int min_args, min_args > 1 ? "s are" : " is"); return -1; } - buf = os_zalloc(sizeof(char) * CMD_BUF_LEN); - if (!buf){ - wpa_printf(MSG_ERROR, "Failed to allocate mem for command buf - %d\n", - CMD_BUF_LEN); - return -1; - } - memset(buf, '\0', CMD_BUF_LEN); + if (write_cmd(buf, CMD_BUF_LEN, cmd, argc, argv) < 0){ ret = -1; goto out; @@ -76,9 +70,6 @@ static int wpa_cli_cmd(struct wpa_ctrl *ctrl, const char *cmd, int min_args, ret = wpa_ctrl_command(ctrl, buf); out: - if (buf) - os_free(buf); - return ret; }