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

TUniqueInstance - Race condition can cause a use-after-free bug #9

Open
WayneSherman opened this issue Jul 2, 2022 · 0 comments
Open

Comments

@WayneSherman
Copy link

Reading through the code, I found what looks like a race condition which can cause a "use-after-free".

When TUniqueInstance is destroyed, FThread is asked to terminate and FSocket is freed:
https://github.com/sysrpl/Codebot.Cross/blob/master/source/codebot/codebot.unique.pas#L77-L79

But the FThread can still be running and attempt to access FSocket after it is freed.
https://github.com/sysrpl/Codebot.Cross/blob/master/source/codebot/codebot.unique.pas#L99

(Imagine the thread checks Terminated and a context switch happens right after that. The main thread then calls TUniqueInstance.Destroy and FSocket is freed. When the thread continues to execute it calls FSocket.Accept(Client), but FSocket has already been freed.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant