Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pthread_cond_timewait can't cope with clock failure #29

Open
sauclovian-g opened this issue Jun 7, 2024 · 1 comment
Open

pthread_cond_timewait can't cope with clock failure #29

sauclovian-g opened this issue Jun 7, 2024 · 1 comment
Labels
help wanted Extra attention is needed

Comments

@sauclovian-g
Copy link

If the timeout isn't null, pthread_cond_timedwait does some work to convert the timeout to a timestamp. If this fails (which it can at least in principle) the resulting error path corrupts the state.

With iStatus != 0, it will not set iLocalWaitingThreads, nor will it attempt to take the semaphore, but it will use the uninitialized value of iLocalWaitingThreads to decrement pxCond->iWaitingThreads. The first decrement attempt in prvTestAndDecrement will most likely fail (though it might not) but prvTestAndDecrement will then retry, and thenceforth the waiter count will be permanently off by one.

This was found by gcc correctly reporting that iLocalWaitingThreads is used uninitialized. FYI.

Fix is to return immediately on error if the timing logic fails.

@shubnil
Copy link
Member

shubnil commented Jun 11, 2024

Thanks for point this out. Will you be willing to create a PR for the same

@shubnil shubnil added the help wanted Extra attention is needed label Jun 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants