threadx icon indicating copy to clipboard operation
threadx copied to clipboard

Potentially missing null check for thread pointer in _tx_mutex_get()

Open szsam opened this issue 1 year ago • 1 comments

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

szsam avatar Feb 07 '24 23:02 szsam

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!

billlamiework avatar Feb 19 '24 20:02 billlamiework