Repository navigation
Conversation
In the TX_MAX_PRIORITIES <= 32 variant of _tx_thread_smp_next_priority_find, the priority map was shifted right by priority before checking if priority exceeded TX_MAX_PRIORITIES. When priority is equal to or greater than 32, shifting a 32-bit unsigned long by 32 or more bits produces undefined behavior in C. The boundary check placed inside the else block was therefore evaluated only after the undefined shift had already taken place. The TX_MAX_PRIORITIES > 32 variant of the same function validates the range upfront before indexing and shifting. The <= 32 variant now mirrors this structure by initializing next_priority to TX_MAX_PRIORITIES and performing the shift and lowest-bit lookup only when priority is within valid bounds. A regression check calling _tx_thread_smp_next_priority_find(TX_MAX_PRIORITIES) has been added to threadx_thread_priority_change.c to exercise the boundary guard and ensure the boundary path is covered. Fixes: eclipse-threadx#680 Signed-off-by: Dev10-sys <kalpanagola9897@gmail.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #680
In
_tx_thread_smp_next_priority_find(whenTX_MAX_PRIORITIES <= 32),local_priority_mapwas shifted right byprioritybefore checking ifprioritywas within range. Ifpriorityis 32 or higher, shifting a 32-bit value by 32 or more bits is undefined behavior in C. Because of this, the range check inside theelseblock was placed after the undefined shift had already happened, making it practically unreachable and leaving it uncovered.The
TX_MAX_PRIORITIES > 32version already handles this properly by checkingpriority < TX_MAX_PRIORITIESupfront before doing any shift. I updated the<= 32version in bothcommon_smp/src/tx_thread_smp_utilities.candcommon_smp/inc/tx_thread.hto match that same logic. Nownext_prioritydefaults toTX_MAX_PRIORITIES, and the shift and bit lookup only run whenpriorityis strictly less thanTX_MAX_PRIORITIES.I also added a test in
test/smp/regression/threadx_thread_priority_change.cthat calls_tx_thread_smp_next_priority_find(TX_MAX_PRIORITIES)directly to make sure it returnsTX_MAX_PRIORITIESsafely without an out-of-range shift. Built and ran the full SMP test suite locally on Linux: all 118 tests pass, and gcov confirms_tx_thread_smp_next_priority_findnow has 100% line coverage.