Skip to content

core/thread: error in thread.c corrected#21253

Merged
maribu merged 4 commits intoRIOT-OS:masterfrom
DeJusten:2025-02.thread
Mar 14, 2025
Merged

core/thread: error in thread.c corrected#21253
maribu merged 4 commits intoRIOT-OS:masterfrom
DeJusten:2025-02.thread

Conversation

@DeJusten
Copy link
Copy Markdown
Contributor

Contribution description

Errors in thread.c corrected:

  • in thread_wakeup() the status of the function to be woken up is incorrectly set to TASK_RUNNING. Instead the task should be set to STATUS_PENDING here, as only sched_run() is allowed to set a task to TASK_RUNNING.
  • in thread_create() it is checked whether the stack is large enough, but instead of aborting the function if the stack is too small and thus preventing a buffer overflow, only a debug output is made. Return statement added
  • in thread_state_to_string() it is not checked whether state is within the valid range, so that in the event of an error an invalid memory address is returned, which in turn leads to further invalid memory accesses when the string is output. thread_state_to_string() is used in particular by ps(). In the case of a corrupt thread context, which often occurred in my case due to the stack size being too small, thread_state_to_string() is called with an invalid status.

Other

  • thread_add_to_list(): Adding the task to the linked list is graphically commented (If you are interested, I also prepared this for core\lib\include\list.h and core\lib\include\clist.h)

Testing procedure

Issues/PRs references

@DeJusten DeJusten requested a review from kaspar030 as a code owner February 28, 2025 12:07
@github-actions github-actions bot added the Area: core Area: RIOT kernel. Handle PRs marked with this with care! label Feb 28, 2025
@benpicco benpicco requested review from kfessel and maribu February 28, 2025 13:01
@mguetschow mguetschow added the CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR label Feb 28, 2025
@riot-ci
Copy link
Copy Markdown

riot-ci commented Feb 28, 2025

Murdock results

✔️ PASSED

2eeb0f7 core/thread: document thread_add_to_list()

Success Failures Total Runtime
10269 0 10269 12m:40s

Artifacts

@mguetschow mguetschow added the Process: needs >1 ACK Integration Process: This PR requires more than one ACK label Mar 4, 2025
@github-actions github-actions bot added the Process: missing approvals Integration Process: PR needs more ACKS (handled by action) label Mar 4, 2025
Return `-EINVAL` when stack is too small in addition to warn when
`ENABLE_DEBUG` is set.
In thread_wakeup() the status of the function to be woken up is
incorrectly set to TASK_RUNNING. Instead the task should be set
to STATUS_PENDING here, as only sched_run() is allowed to set a
task to TASK_RUNNING.
@maribu
Copy link
Copy Markdown
Member

maribu commented Mar 14, 2025

@DeJusten thanks a lot for the PR. I was so free to split the fixes into one commit per fix and to apply @kfessel's suggestion.

@maribu
Copy link
Copy Markdown
Member

maribu commented Mar 14, 2025

(If you are interested, I also prepared this for core\lib\include\list.h and core\lib\include\clist.h)

Yes, we would :)

@maribu maribu requested a review from kfessel March 14, 2025 10:08
Copy link
Copy Markdown
Contributor

@kfessel kfessel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please reduce the number of static test warnings (not for the style but these warnings are annoying when reviewing)

just found that both of these warning are in my prior suggestion -- sorry for that

@github-actions github-actions bot removed the Process: missing approvals Integration Process: PR needs more ACKS (handled by action) label Mar 14, 2025
In thread_state_to_string() it is not checked whether state is within
the valid range, so that in the event of an error an invalid memory
address is returned, which in turn leads to further invalid memory
accesses when the string is output. thread_state_to_string() is used
in particular by ps(). In the case of a corrupt thread context, which
often occurred in my case due to the stack size being too small,
thread_state_to_string() is called with an invalid status.
Adding the task to the linked list is graphically commented
@maribu maribu enabled auto-merge March 14, 2025 12:14
@maribu maribu added this pull request to the merge queue Mar 14, 2025
Merged via the queue into RIOT-OS:master with commit 785faa7 Mar 14, 2025
25 checks passed
@mguetschow mguetschow added this to the Release 2025.04 milestone Apr 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area: core Area: RIOT kernel. Handle PRs marked with this with care! CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR Process: needs >1 ACK Integration Process: This PR requires more than one ACK

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants