fix: TOCTOU race condition in vTaskListTasks()#1431
Merged
AniruddhaKanhere merged 1 commit intoJun 19, 2026
Conversation
Read uxCurrentNumberOfTasks once into uxArraySize and use that local variable for both the size check and pvPortMalloc() call. The previous code read the volatile variable twice, allowing a task to be created between the reads, resulting in an undersized allocation that could cause a buffer overflow in uxTaskGetSystemState().
AniruddhaKanhere
approved these changes
Jun 19, 2026
AniruddhaKanhere
left a comment
Member
There was a problem hiding this comment.
Thank you for your contribution @srpatcha!
This looks good to me. Approved!
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1431 +/- ##
==========================================
- Coverage 91.37% 91.28% -0.10%
==========================================
Files 6 6
Lines 3259 3269 +10
Branches 902 905 +3
==========================================
+ Hits 2978 2984 +6
- Misses 132 135 +3
- Partials 149 150 +1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
gmtt
approved these changes
Jun 19, 2026
|
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.



Description
vTaskListTasks() and vTaskList() read the volatile uxCurrentNumberOfTasks twice: once for the zero-check and once for pvPortMalloc(). If a task is created between the two reads, the allocated buffer is undersized, causing a potential buffer overflow in uxTaskGetSystemState().
Fix
Use the local variable uxArraySize (already assigned from uxCurrentNumberOfTasks) for the pvPortMalloc() call instead of re-reading the volatile.
Changes
Split from #1409 per reviewer request to separate the bug fix from .editorconfig changes.