Skip to content

feat(kernel): Enforce uxListRemove Precondition with Assertion #1288

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

kernelpoetlaureate
Copy link

Right now, uxListRemove() blindly dereferences pxItemToRemove->pxContainer to get the parent list. If an item is removed twice, the second removal leads to a NULL dereference and potentially very tricky bugs—memory corruption or random hard faults that show up far from the original mistake.


Reproducing the Issue

This minimal test case demonstrates the bug clearly:

void vDemonstrateDoubleRemoveFailure( void )
{
    List_t xMyList;
    ListItem_t xMyItem;

    vListInitialise( &xMyList );
    vListInitialiseItem( &xMyItem );

    // Insert the item—everything valid so far.
    vListInsert( &xMyList, &xMyItem );

    // First removal: valid. The container is now NULL.
    uxListRemove( &xMyItem );

    // Second removal: not valid. pxContainer is NULL—boom.
    uxListRemove( &xMyItem );
}

The Fix

Simply adding this line at the beginning of uxListRemove() makes the contract explicit:

configASSERT( pxItemToRemove->pxContainer != NULL );

This stops the function immediately if it's called with an invalid state, turning a subtle landmine into a clear, actionable failure.


Impact

  • Performance & Code Size: None at all in production—configASSERT compiles away when assertions are disabled.
  • Debuggability: Huge win. It turns an obscure crash into an instant diagnostic message.
  • Compatibility: 100% backward-compatible. This only catches code that was already incorrect.

@kernelpoetlaureate kernelpoetlaureate requested a review from a team as a code owner July 2, 2025 10:53
@aggarg
Copy link
Member

aggarg commented Jul 2, 2025

FreeRTOS List is internal data structure not intended for application use. The List API may change even between minor versions. Are you experiencing any issues while using FreeRTOS's public APIs?

Copy link

sonarqubecloud bot commented Jul 3, 2025

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.

2 participants