eclipse-threadx / threadx

Eclipse ThreadX is an advanced real-time operating system (RTOS) designed specifically for deeply embedded applications.
https://github.com/eclipse-threadx/rtos-docs/blob/main/rtos-docs/threadx/index.md
MIT License
2.8k stars 767 forks source link

Potentially missing null check for thread pointer in _tx_mutex_get() #356

Open szsam opened 4 months ago

szsam commented 4 months ago

The pointer thread_ptr is checked for null here: https://github.com/eclipse-threadx/threadx/blob/d64ef2ab064047ab5aed15c7861e5a44ab8022e3/common/src/tx_mutex_get.c#L122-L168

But it is not checked in the following block: https://github.com/eclipse-threadx/threadx/blob/d64ef2ab064047ab5aed15c7861e5a44ab8022e3/common/src/tx_mutex_get.c#L208-L395

billlamiework commented 4 months ago

The rule is that tx_mutex_get cannot be called from a non-thread context with a suspension option. This is checked for in the error checking for tx_mutex_get, namely txe_mutex_get. Error checking is enabled by default. If the application bypasses error checking it must be calling all APIs from the correct context.

As for the earlier check for thread_ptr non-NULL is to handle the call of tx_mutex_get from initialization (where thread_ptr is NULL).

I hope that helps explain what is going on!