Skip to content

fix: guard against NULL return from CFE_ES_LocateTaskRecordByID in StartAppTask#2759

Open
stark256-spec wants to merge 1 commit into
nasa:devfrom
stark256-spec:fix/null-deref-start-app-task
Open

fix: guard against NULL return from CFE_ES_LocateTaskRecordByID in StartAppTask#2759
stark256-spec wants to merge 1 commit into
nasa:devfrom
stark256-spec:fix/null-deref-start-app-task

Conversation

@stark256-spec

Copy link
Copy Markdown

Summary

Fixes #2491

Problem

In CFE_ES_StartAppTask, the return value of CFE_ES_LocateTaskRecordByID was used without a null check. The function can return NULL when the resource ID is out of range, leading to a null pointer dereference at the subsequent CFE_ES_TaskRecordIsUsed() call and memset(). This was flagged by Klocwork static analysis.

Fix

Add a null check immediately after CFE_ES_LocateTaskRecordByID, following the same pattern used in CFE_ES_AppCreate (where LocateAppRecordByID is already guarded):

  • If TaskRecPtr == NULL: log the error, call OS_TaskDelete on the newly created OSAL task to avoid leaking the OS resource, set CFE_ES_NO_RESOURCE_IDS_AVAILABLE, and return.
  • Otherwise: continue with existing logic (in-use check, memset, field initialization).

Test plan

  • Existing ES unit tests pass
  • Static analysis (Klocwork) no longer flags this path

…artAppTask

CFE_ES_LocateTaskRecordByID can return NULL if the resource ID is out of
range. In CFE_ES_StartAppTask, the return value was used without a null
check, causing a potential null pointer dereference at the subsequent
CFE_ES_TaskRecordIsUsed() call and memset().

Add a null check matching the pattern used in CFE_ES_AppCreate: if no
slot is available, delete the newly created OS task to avoid leaking
the OSAL resource, log the error, and return CFE_ES_NO_RESOURCE_IDS_AVAILABLE.

Fixes nasa#2491
@stark256-spec

Copy link
Copy Markdown
Author

Checking in on this one — static analysis flagged a real NULL-deref path here and the fix is small and self-contained. If there's a preferred reviewer for ES-module changes, happy to tag them directly. Let me know if anything needs adjusting before this goes to CCB.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Possible NULL ptr deference in CFE_ES_StartAppTask

2 participants