Skip to content
Tcl Source Code Ticket Change Details
Login

Ticket Change Details

Overview

Artifact ID: 71126824be9fcce60db82177871692507270387bc0198f75aa793eb7d750ee35
Ticket: 24949cbd7cb727c6ce8927ad6a7da6efe0d8ec59
Many functions of tclPathObj are not thread safe (can segfault by changing of FS epoch)
User & Date: sebres on 2021-08-10 12:45:25
Changes

  1. assignee changed to: "nobody"
  2. closer changed to: "nobody"
  3. cmimetype changed to: "text/x-fossil-wiki"
  4. comment changed to:
    I was searching for the heisenbug, occurring extremely rare at initialization phase of a (multithreaded) tcl-application.
    
    The callstack shows:
    <pre style="padding-left:10pt"><code>
    Thread 9 received signal SIGSEGV, Segmentation fault.
    [Switching to Thread 18320.0x1c0c]
    0x50589c0b in tcl85!Tcl_GetStringFromObj () from ./tcl85.dll
    (gdb) bt
    #0  0x50589c0b in tcl85!Tcl_GetStringFromObj () from ./tcl85.dll
    #1  0x505d9e87 in tcl85!TclpMatchInDirectory () from ./tcl85.dll
    #2  0x50575db6 in tcl85!Tcl_FSMatchInDirectory () from ./tcl85.dll
    ...
    #35 0x505962fc in tcl85!Tcl_PkgRequireEx () from ./tcl85.dll
    </code></pre>
    
    After analyzing the code in TclpMatchInDirectory and tclPathObj, the error is obvious - it is occurred by [./file?ci=1b84e484da461b64&name=win%2FtclWinFile.c&ln=981-1007|win/tclWinFile.c&ln=981-1007] in ln. 1007 when between ln. 981 and ln. 990 some other thread changing the FS epoch, so the object <code>pathPtr</code> invalidates the internal representation and <code>fileNamePtr</code> disappears.<br/>
    (Indirectly, this going to the [./file?ci=1b84e484da461b64&name=generic/tclPathObj.c&ln=1175|Tcl_FSConvertToPathType] which can invalidate the object if check with TclFSEpochOk shows modification of FS epoch, which is system wide so can occur in other thread).
    
    One could surely increment the reference of <code>fileNamePtr</code> in TclpMatchInDirectory temporarily, but there are too many code pieces (inclusive tclPathObj.c itself) with the assumption that if path-object can't shimmer, its internal representation remains the same, what is obviously not the case by this approach considering the system wide epoch.
    
    If this issue cannot be solved using different common approach, the whole code using several path-API functions (in generic/ but also in win/ and unix/) must be reviewed, e. g. extended with incr+decr ref-count for many objects comming from internal representation of path-type objects using Tcl-API or direct assignment.
    
  5. foundin changed to: ">= 8.5"
  6. is_private changed to: "0"
  7. login: "sebres"
  8. priority changed to: "5 Medium"
  9. resolution changed to: "None"
  10. severity changed to: "Critical"
  11. status changed to: "Open"
  12. submitter changed to: "sebres"
  13. subsystem changed to: "36. Pathname Management"
  14. title changed to:
    Many functions of tclPathObj are not thread safe (can segfault by changing of FS epoch)
    
  15. type changed to: "Bug"