Skip to content
Tcl Source Code History Of Ticket e2698b94b1
Login

History Of Ticket e2698b94b1

Artifacts Associated With Ticket e2698b94b1

  1. Ticket change [93c7bf9b8d] (rid 252791) by jmroot on 2026-04-14 23:48:01:

    1. assignee initialized to: "nobody"
    2. closer initialized to: "nobody"
    3. cmimetype initialized to: "text/x-fossil-plain"
    4. comment initialized to:
      Tcl_FSChdir can trigger thousands of levels of recursion and finally crash in some circumstances. The attached reproducer will crash when run as root from a directory that is inaccessible to 'nobody'. It's as minimal as I could get it; removing either of the Tcl_FSGetCwd calls seems to avoid the crash.
      
      This was discovered in MacPorts, where the issue can easily be triggered by the user running 'sudo port ...' from their home directory (since it is typically not accessible to the account used for dropping privileges). The crash happens when it calls pwd and cd at the script level: [https://github.com/macports/macports-base/blob/master/src/port1.0/portutil.tcl#L1419]
      
      I'm also attaching the crash log generated by running the reproduction program when linked with Tcl built with debug information and clang sanitizers (hence the weird stuff at the top of the stack trace).
      
    5. foundin initialized to: "9.0.3"
    6. is_private initialized to: "0"
    7. login: "jmroot"
    8. priority initialized to: "5 Medium"
    9. private_contact initialized to: "76145175b6ffee50eff3d492ff299da342ff102d"
    10. resolution initialized to: "None"
    11. severity initialized to: "Severe"
    12. status initialized to: "Open"
    13. submitter initialized to: "jmroot"
    14. subsystem initialized to: "36. Pathname Management"
    15. title initialized to: "Tcl_FSChdir crashes after seteuid"
    16. type initialized to: "Bug"
  2. Add attachment "cd_crash.c" [c4e1309d07] (rid 252792) by jmroot on 2026-04-14 23:48:41.

  3. Add attachment "crash.log" [ed035a9a46] (rid 252793) by jmroot on 2026-04-14 23:50:40.

  4. Ticket change [e704995854] (rid 252802) by apnadkarni on 2026-04-16 05:47:20:

    1. icomment:
      I could not reproduce this on Ubuntu 22 but that could very well be because I'm running under WSL and behavior of getcwd() etc. on NTFS could very well be different as far as access permissions go. In fact, the test suite already disables chmod related tests for WSL.
      
      Looking at the source code, it appears the recursion case happens [here](https://core.tcl-lang.org/tcl/file?ci=b6a50a0482cf3db3&name=generic%2FtclPathObj.c&ln=1869) where the path value is "". How it gets to be the empty string is a question but I suspect somewhere getcwd returns NULL on error and that gets translated to the empty string. That's just conjecture.
      
      The comment there
      
      ```
      	     * Special handling for the empty string value. This one is very
      	     * weird with [file normalize {}] => {}. (The reasoning supporting
      	     * this is unknown to DGP, but he fears changing it.) Attempt here
      	     * to keep the expectations of other parts of Tcl_Filesystem code
      	     * about state of the FsPath fields satisfied.
      ```
      
      is rather telling but I'm in the same boat as DGP in that regard.
      
      If @jmr or someone running macos can trace and check if the path is in fact "" at that point, it would help track this down.
      
    2. login: "apnadkarni"
    3. mimetype: "text/x-markdown"
  5. Ticket change [5ac8a1a47a] (rid 252803) by apnadkarni on 2026-04-16 06:30:55:

    1. icomment:
      Ok, I was able to reproduce this behavior by hacking getcwd to return NULL after the seteuid() call and can confirm it results in the current directory being set to the empty string which then results in the recursive crash you saw.
      
      Examining for potential fixes...
      
      Thanks much for the detailed crash and short test case. Would not have been possible for me to tackle this otherwise.
      
    2. login: "apnadkarni"
    3. mimetype: "text/x-markdown"
  6. Ticket change [d602dcc00b] (rid 252804) by jmroot on 2026-04-16 08:02:43:

    1. icomment:
      Thanks. I modified the test program to call getcwd directly and print the result, and can confirm that it returns a NULL pointer after the seteuid on macOS.
      
    2. login: "jmroot"
    3. mimetype: "text/plain"
  7. Ticket change [1256b86593] (rid 252832) by apnadkarni on 2026-04-17 05:40:17:

    1. icomment:
      @jmroot, could you try the [bug-e2698b94b1](https://core.tcl-lang.org/tcl/timeline?r=bug-e2698b94b1) branch and see if that works better for you? The sample test case no longer crashes but I can't test your real scenario.
      
    2. login: "apnadkarni"
    3. mimetype: "text/x-markdown"
  8. Ticket change [d7a481f7b2] (rid 252834) by jmroot on 2026-04-17 07:12:12:

    1. icomment:
      Applying that change prevents the crash in MacPorts. Thank you!
      
    2. login: "jmroot"
    3. mimetype: "text/plain"
  9. Ticket change [19d00257e3] (rid 252845) by apnadkarni on 2026-04-17 11:10:30:

    1. closedate changed to: "2461147.9656304629"
    2. closer changed to: "apnadkarni"
    3. icomment:
      Great. Committed to core-9-0-branch and main.
      
      Did this come up because of some change in macports or something new with Tcl 9?
      
      Closing.
      
    4. login: "apnadkarni"
    5. mimetype: "text/plain"
    6. resolution changed to: "Fixed"
    7. status changed to: "Closed"
  10. Ticket change [b934fa2805] (rid 252859) by jmroot on 2026-04-17 23:38:11:

    1. closedate changed to: "2461148.4848590395"
    2. closer changed to: "jmroot"
    3. icomment:
      It seems to have been new with Tcl 9 since MacPorts did not see the issue when using 8.6.17.
      
    4. login: "jmroot"
    5. mimetype: "text/plain"
  11. Ticket change [d2ede87251] (rid 252860) by apnadkarni on 2026-04-18 02:22:40:

    1. closedate changed to: "2461148.5990786804"
    2. closer changed to: "apnadkarni"
    3. icomment:
      Right, should have realized that without asking. The recursion is through the zipfs file system as your trace showed, which of course is not present in 8.6 by default.
      
      I suspect it may have shown up in 8.6 as well if a VFS was mounted (depending on the VFS).
      
    4. login: "apnadkarni"
    5. mimetype: "text/plain"