Skip to content
Tcl Source Code History Of Ticket 7c2716733a526ba6
Login

History Of Ticket 7c2716733a526ba6

Artifacts Associated With Ticket 7c2716733a526ba6

  1. Ticket change [a510689999] (rid 241290) by apnadkarni on 2025-06-13 11:13:49:

    1. assignee initialized to: "nobody"
    2. closer initialized to: "nobody"
    3. cmimetype initialized to: "text/x-markdown"
    4. comment initialized to:
      Running the Windows application verifier on trunk shows a use after free on a Windows event handle used for exec pipes. The offending line is [here](https://core.tcl-lang.org/tcl/file?ci=950d15a307bcbf94&name=win/tclWinPipe.c&ln=3415).
      
      The `SetEvent` generally returns an invalid handle error in this case and we happily ignore the error so it is undetected and life goes on. However, if by chance (however small) the handle value were to be reused by Windows for a different handle, unexpected behaviour would occur as it would not be treated as an invalid handle.
      
      This should be afforded the same level of importance as a user-after-free detected by valgrind.
      
    5. foundin initialized to: "trunk"
    6. is_private initialized to: "0"
    7. login: "apnadkarni"
    8. priority initialized to: "5 Medium"
    9. private_contact initialized to: "9546e9877f1a8899e25a89082561ee694e7fb402"
    10. resolution initialized to: "None"
    11. severity initialized to: "Important"
    12. status initialized to: "Open"
    13. submitter initialized to: "apnadkarni"
    14. subsystem initialized to: "- New Builtin Commands"
    15. title initialized to:
      App Verifier shows use-after-free on event handle for Windows pipes
      
    16. type initialized to: "Bug"
  2. Ticket change [7490cd239f] (rid 241291) by apnadkarni on 2025-06-13 11:48:28:

    1. icomment:
      Looking at the source, the event handle seems to have been already closed [here](https://core.tcl-lang.org/tcl/file?ci=950d15a307bcbf94&name=win/tclWinPipe.c&ln=2037).
      
      It *seems* to me that the immediately preceding `TclPipeThreadStop` wakes up the worker thread, transitioning it to the STOP state where it invokes SetEvent(). In the meanwhile, the code after `TclPipeThreadStop` immediately closes that event handle before the worker actually runs. Hence the invalid handle error.
      
      I don't know what the synchronization protocol is between the main and worker threads so leaving investigation and fix to those who do.
      
      As an aside, seems like this extends way back to 8.6.
      
    2. login: "apnadkarni"
    3. mimetype: "text/x-markdown"
  3. Ticket change [e6d35a9384] (rid 241454) by apnadkarni on 2025-06-14 14:31:09:

    1. icomment:
      Proposed fix is [here](https://core.tcl-lang.org/tcl/info/e85c44529a9b3d58).
      
      Looking more closely at the code, I did not see why that event handle was needed at all. In summary,
      
      * the handle in question is `TclPipeThreadInfo.evWakeup`. This is initialized from the `readable` or `writable` event handles from the channel structure.
      
      * the worker thread however signal read or write completions directly using the `readable`/`writable` handles from the channel structure, not evWakeup.
      
      * the only time `TclPipeThreadInfo.evWakeup` is signalled is on worker thread exit which is when it has already been deallocated by the main thread causing the use-after-free error!
      
      The proposed fix simply expunges all references to the `TclPipeThreadInfo.evWakeup`. The test suite passes and Application Verifier no longer complains. But someone should review before merge.
      
    2. login: "apnadkarni"
    3. mimetype: "text/x-markdown"
  4. Ticket change [4f217b01c0] (rid 241979) by apnadkarni on 2025-06-25 16:24:23:

    1. closedate changed to: "2460852.18360263"
    2. closer changed to: "apnadkarni"
    3. icomment: "Fixed in [7c2716733a]."
    4. login: "apnadkarni"
    5. mimetype: "text/x-fossil-plain"
    6. resolution changed to: "Fixed"
    7. status changed to: "Closed"