fix(network_provisioning): adds more checks for received messages#711
Conversation
6452a90 to
186c4d9
Compare
There was a problem hiding this comment.
Pull request overview
This PR hardens the network provisioning protobuf handlers by adding input validation for malformed/incorrectly-shaped messages and tightening up memory management during scan/config operations.
Changes:
- Added
payload_case+ pointer validation before dereferencing command payloads (WiFi/Thread scan + config set handlers). - Prevented Thread dataset copy when the incoming dataset length exceeds the fixed buffer.
- Fixed a leak in WiFi scan result cleanup by freeing each allocated entry struct.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
network_provisioning/src/network_scan.c |
Adds request payload validation; adds an OOM return in Thread scan result path; fixes WiFi scan result entry cleanup leak. |
network_provisioning/src/network_config.c |
Adds request payload validation for set-config commands; moves Thread dataset memcpy behind a length check to avoid overflow. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
186c4d9 to
dca0077
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
Comments suppressed due to low confidence (1)
network_provisioning/src/network_scan.c:259
- resp_payload->n_entries is set to the requested count before the loop, but the loop can break early on errors, leaving NULL (or partially initialized) entries while n_entries still indicates they are present. protobuf-c will attempt to pack all n_entries elements and can crash when it hits a NULL element or a bytes field with len>0 and data==NULL. Track the number of successfully built entries and set n_entries accordingly; on per-entry failure, free/NULL out the partially built entry and exclude it from n_entries.
resp_payload->entries = results;
resp_payload->n_entries = req->cmd_scan_wifi_result->count;
/* If req->cmd_scan_wifi_result->count is 0, the below loop will
* be skipped.
*/
for (uint16_t i = 0; i < req->cmd_scan_wifi_result->count; i++) {
if (!h->wifi_scan_result) {
resp->status = STATUS__InternalError;
break;
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
dca0077 to
613560a
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
613560a to
d3aa8f4
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
d3aa8f4 to
6c5fe6b
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
@Ashish285 minor comments, but otherwise MR LGTM. |
30b9c4f to
55b82a2
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
55b82a2 to
156da7f
Compare
|
I did some tests to check if the memory leak was indeed there. To create "memory leaks", I just set one buffer check after malloc to be always true, so it thinks that the malloc failed. These are the results On current master:
Complete Logs
I (16177) app: Secured session established! With current branch
Complete Logs
I (16197) app: Secured session established! |
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
156da7f to
f6e20a1
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
f6e20a1 to
be42203
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.
Comments suppressed due to low confidence (1)
network_provisioning/src/network_config.c:445
- In the Thread status cleanup path,
ThreadAttachState.ext_pan_id.datais allocated incmd_get_status_handlerwhen attached, but it is never freed here. This will leak memory each time an attached Thread status response is built/cleaned up. Freethread_attached->ext_pan_id.data(when non-NULL) before freeingthread_attacheditself.
if (!resp->resp_get_thread_status) {
break;
}
#ifdef CONFIG_NETWORK_PROV_NETWORK_TYPE_THREAD
switch (resp->resp_get_thread_status->thread_state) {
case THREAD_NETWORK_STATE__Attaching:
break;
case THREAD_NETWORK_STATE__Attached:
if (resp->resp_get_thread_status->thread_attached) {
if (resp->resp_get_thread_status->thread_attached->name) {
free(resp->resp_get_thread_status->thread_attached->name);
}
free(resp->resp_get_thread_status->thread_attached);
}
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
@wqx6 PTAL |
|
@Ashish285 Please add change-log entry, bump component version |
be42203 to
18ff4af
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Checklist
Change description
This PR adds in more input validations and fixes some memory issues