Skip to content

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

@WayneSherman

Description

@WayneSherman

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.)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions