Skip to content

Guard against null dereference on missing/non-numeric "state" field in GetWifiState JSON parsing - #406

Merged
Vismalskumar0 merged 2 commits into
feature/RDKEMW-14686_finalfrom
copilot/sub-pr-399-99188a72-80ca-40d1-95d2-38f429faca17
Mar 12, 2026
Merged

Guard against null dereference on missing/non-numeric "state" field in GetWifiState JSON parsing#406
Vismalskumar0 merged 2 commits into
feature/RDKEMW-14686_finalfrom
copilot/sub-pr-399-99188a72-80ca-40d1-95d2-38f429faca17

Conversation

Copilot AI commented Mar 12, 2026

Copy link
Copy Markdown
Contributor

Accessing state->valueint in the GetWifiState block had no null or type check — if the JSON response omitted "state" or returned it as a non-numeric type, the code would dereference a null pointer.

Changes

  • Device_WiFi_SSID.cpp: Added !state || !cJSON_IsNumber(state) guard immediately after cJSON_GetObjectItem(jsonObj, "state"), before any access to state->valueint. Returns NOK with an error log on failure.
cJSON *state = cJSON_GetObjectItem(jsonObj, "state");
if (!state || !cJSON_IsNumber(state))
{
    RDK_LOG(RDK_LOG_ERROR, LOG_TR69HOSTIF,
            "[%s] json parse error, \"state\" field missing or not a number\n", __FUNCTION__);
    cJSON_Delete(root);
    return NOK;
}
int res = state->valueint;

Consistent with the validation pattern used for "state" in Device_WiFi_EndPoint.cpp.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

…n GetWifiState

Co-authored-by: Vismalskumar0 <188226757+Vismalskumar0@users.noreply.github.com>
Copilot AI changed the title [WIP] Update Device_WiFi_SSID.cpp Guard against null dereference on missing/non-numeric "state" field in GetWifiState JSON parsing Mar 12, 2026
@Vismalskumar0
Vismalskumar0 marked this pull request as ready for review March 12, 2026 11:12
@Vismalskumar0
Vismalskumar0 requested a review from a team as a code owner March 12, 2026 11:12
Copilot AI review requested due to automatic review settings March 12, 2026 11:12
@Vismalskumar0
Vismalskumar0 merged commit 7240484 into feature/RDKEMW-14686_final Mar 12, 2026
1 check passed
@github-actions github-actions Bot locked and limited conversation to collaborators Mar 12, 2026
Copilot AI removed the request for review from Copilot March 23, 2026 22:43
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants