mirror of
https://github.com/espressif/esp-idf
synced 2025-03-10 01:29:21 -04:00
wifi_provisioning: Add a check for number of scanned networks while allocating memory
If number of scanned networks is zero, while getting the list, since we try to allocate zero bytes, we get a NULL pointer in response. This is considered as an error and the provisioning worflow breaks there. Adding a check before allocation resolves the issue.
This commit is contained in:
parent
317c882133
commit
388f4fd7ef
@ -134,16 +134,21 @@ static esp_err_t cmd_scan_result_handler(WiFiScanPayload *req,
|
|||||||
resp->status = STATUS__Success;
|
resp->status = STATUS__Success;
|
||||||
resp->payload_case = WI_FI_SCAN_PAYLOAD__PAYLOAD_RESP_SCAN_RESULT;
|
resp->payload_case = WI_FI_SCAN_PAYLOAD__PAYLOAD_RESP_SCAN_RESULT;
|
||||||
resp->resp_scan_result = resp_payload;
|
resp->resp_scan_result = resp_payload;
|
||||||
|
/* Allocate memory only if there are non-zero scan results */
|
||||||
results = (WiFiScanResult **) calloc(req->cmd_scan_result->count,
|
if (req->cmd_scan_result->count) {
|
||||||
sizeof(WiFiScanResult *));
|
results = (WiFiScanResult **) calloc(req->cmd_scan_result->count,
|
||||||
if (!results) {
|
sizeof(WiFiScanResult *));
|
||||||
ESP_LOGE(TAG, "Failed to allocate memory for results array");
|
if (!results) {
|
||||||
return ESP_ERR_NO_MEM;
|
ESP_LOGE(TAG, "Failed to allocate memory for results array");
|
||||||
|
return ESP_ERR_NO_MEM;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
resp_payload->entries = results;
|
resp_payload->entries = results;
|
||||||
resp_payload->n_entries = req->cmd_scan_result->count;
|
resp_payload->n_entries = req->cmd_scan_result->count;
|
||||||
|
|
||||||
|
/* If req->cmd_scan_result->count is 0, the below loop will
|
||||||
|
* be skipped.
|
||||||
|
*/
|
||||||
for (uint16_t i = 0; i < req->cmd_scan_result->count; i++) {
|
for (uint16_t i = 0; i < req->cmd_scan_result->count; i++) {
|
||||||
err = h->scan_result(i + req->cmd_scan_result->start_index,
|
err = h->scan_result(i + req->cmd_scan_result->start_index,
|
||||||
&scan_result, &h->ctx);
|
&scan_result, &h->ctx);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user