Skip to content

Commit 3b5fcbe

Browse files
kapilkedawatespressif-bot
authored andcommitted
wpa_supplicant: Fix some memleaks and invalid memory access
Add changes to fix issues reported in clang analyzer
1 parent d5195d1 commit 3b5fcbe

File tree

3 files changed

+30
-22
lines changed

3 files changed

+30
-22
lines changed

components/wpa_supplicant/src/esp_supplicant/esp_wpa2.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -759,6 +759,7 @@ static int eap_peer_sm_init(void)
759759
if (ret) {
760760
wpa_printf(MSG_ERROR, "eap_peer_blob_init failed\n");
761761
os_free(sm);
762+
vSemaphoreDelete(s_wpa2_data_lock);
762763
return ESP_FAIL;
763764
}
764765

@@ -767,6 +768,7 @@ static int eap_peer_sm_init(void)
767768
wpa_printf(MSG_ERROR, "eap_peer_config_init failed\n");
768769
eap_peer_blob_deinit(sm);
769770
os_free(sm);
771+
vSemaphoreDelete(s_wpa2_data_lock);
770772
return ESP_FAIL;
771773
}
772774

@@ -777,6 +779,7 @@ static int eap_peer_sm_init(void)
777779
eap_peer_blob_deinit(sm);
778780
eap_peer_config_deinit(sm);
779781
os_free(sm);
782+
vSemaphoreDelete(s_wpa2_data_lock);
780783
return ESP_FAIL;
781784
}
782785

@@ -788,6 +791,12 @@ static int eap_peer_sm_init(void)
788791
xTaskCreate(wpa2_task, "wpa2T", WPA2_TASK_STACK_SIZE, NULL, 2, s_wpa2_task_hdl);
789792
s_wifi_wpa2_sync_sem = xSemaphoreCreateCounting(1, 0);
790793
if (!s_wifi_wpa2_sync_sem) {
794+
vQueueDelete(s_wpa2_queue);
795+
s_wpa2_queue = NULL;
796+
eap_peer_blob_deinit(sm);
797+
eap_peer_config_deinit(sm);
798+
os_free(sm);
799+
vSemaphoreDelete(s_wpa2_data_lock);
791800
wpa_printf(MSG_ERROR, "WPA2: failed create wifi wpa2 task sync sem");
792801
return ESP_FAIL;
793802
}

components/wpa_supplicant/src/wps/wps.c

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -260,42 +260,40 @@ int wps_is_addr_authorized(const struct wpabuf *msg, const u8 *addr,
260260
* provisioning, -1 if wps_a is considered more like, or 0 if no preference
261261
*/
262262
int wps_ap_priority_compar(const struct wpabuf *wps_a,
263-
const struct wpabuf *wps_b)
263+
const struct wpabuf *wps_b)
264264
{
265-
struct wps_parse_attr *attr_a, *attr_b;
265+
struct wps_parse_attr *attr = NULL;
266266
int sel_a, sel_b;
267-
int ret = 0;
267+
int ret = 0; /* No preference */
268268

269-
attr_a = (struct wps_parse_attr *)os_zalloc(sizeof(struct wps_parse_attr));
270-
attr_b = (struct wps_parse_attr *)os_zalloc(sizeof(struct wps_parse_attr));
269+
attr = os_zalloc(sizeof(*attr));
271270

272-
if (attr_a == NULL || attr_b == NULL) {
273-
ret = 0;
274-
goto _out;
275-
}
271+
if (!attr)
272+
return ret;
276273

277-
if (wps_a == NULL || wps_parse_msg(wps_a, attr_a) < 0)
278-
return 1; // NOLINT(clang-analyzer-unix.Malloc)
279-
if (wps_b == NULL || wps_parse_msg(wps_b, attr_b) < 0)
280-
return -1;
274+
if (wps_a == NULL || wps_parse_msg(wps_a, attr) < 0) {
275+
ret = 1;
276+
goto exit;
277+
}
278+
sel_a = attr->selected_registrar && *(attr->selected_registrar) != 0;
281279

282-
sel_a = attr_a->selected_registrar && *attr_a->selected_registrar != 0;
283-
sel_b = attr_b->selected_registrar && *attr_b->selected_registrar != 0;
280+
if (wps_b == NULL || wps_parse_msg(wps_b, attr) < 0) {
281+
ret = -1;
282+
goto exit;
283+
}
284+
sel_b = attr->selected_registrar && *(attr->selected_registrar) != 0;
284285

285286
if (sel_a && !sel_b) {
286287
ret = -1;
287-
goto _out;
288+
goto exit;
288289
}
289290
if (!sel_a && sel_b) {
290291
ret = 1;
291-
goto _out;
292+
goto exit;
292293
}
293294

294-
_out:
295-
if (attr_a)
296-
os_free(attr_a);
297-
if (attr_b)
298-
os_free(attr_b);
295+
exit:
296+
os_free(attr);
299297
return ret;
300298
}
301299

components/wpa_supplicant/src/wps/wps_registrar.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1640,6 +1640,7 @@ int wps_build_cred(struct wps_data *wps, struct wpabuf *msg)
16401640
if (random_get_bytes(r, sizeof(r)) < 0)
16411641
return -1;
16421642
os_free(wps->new_psk);
1643+
wps->new_psk = (u8 *)base64_encode(r, sizeof(r), &wps->new_psk_len);
16431644
if (wps->new_psk == NULL)
16441645
return -1;
16451646
wps->new_psk_len--; /* remove newline */

0 commit comments

Comments
 (0)