|
2026-11-23
| ||
| 17:50 | Fix [e2698b94b1]: Tcl_FSChdir crash on macos/macports after seteuid check-in: 018bd193b2 user: jan.nijtmans tags: core-8-6-branch | |
| 13:32 | • Ticket [4d3f213029] VFS support causes infinite recursion during 'file exist... artifact: 1b6add3f04 user: serhiy.storchaka | |
| 13:31 | Fix [4d3f213029] on 8.6: backport [82a62c58b9] (fix for [e2698b94b1]). When getcwd() fails, Tcl_FSGe... closed check-in: e590554a8f user: serhiy.storchaka tags: getcwd-failure-8-6 | |
|
2026-04-18
| ||
| 02:22 | • Ticket [e2698b94b1] Tcl_FSChdir crashes after seteuid status still Closed wi... artifact: d2ede87251 user: apnadkarni | |
|
2026-04-17
| ||
| 23:38 | • Ticket [e2698b94b1]: 5 changes artifact: b934fa2805 user: jmroot | |
| 11:10 | • Closed ticket [e2698b94b1]. artifact: 19d00257e3 user: apnadkarni | |
| 11:08 | Merge 9.0 - Fix [e2698b94b1]. Tcl_FSChdir crash on macos/macports after seteuid check-in: 0853fd5d4a user: apnadkarni tags: trunk, main | |
| 10:45 | Fix [e2698b94b1]. Tcl_FSChdir crash on macos/macports after seteuid check-in: 82a62c58b9 user: apnadkarni tags: core-9-0-branch | |
| 07:12 | • Ticket [e2698b94b1] Tcl_FSChdir crashes after seteuid status still Open with... artifact: d7a481f7b2 user: jmroot | |
| 05:40 | • Ticket [e2698b94b1]: 3 changes artifact: 1256b86593 user: apnadkarni | |
| 04:04 | Start on [e2698b94b1]. Tcl_FSChdir crash on macos after seteuid closed check-in: 7e7e1d3904 user: apnadkarni tags: bug-e2698b94b1 | |
|
2026-04-16
| ||
| 08:02 | • Ticket [e2698b94b1] Tcl_FSChdir crashes after seteuid status still Open with... artifact: d602dcc00b user: jmroot | |
| 06:30 | • Ticket [e2698b94b1]: 3 changes artifact: 5ac8a1a47a user: apnadkarni | |
| 05:47 | • Ticket [e2698b94b1]: 3 changes artifact: e704995854 user: apnadkarni | |
|
2026-04-14
| ||
| 23:50 | • Add attachment crash.log to ticket [e2698b94b1] artifact: ed035a9a46 user: jmroot | |
| 23:48 | • Add attachment cd_crash.c to ticket [e2698b94b1] artifact: c4e1309d07 user: jmroot | |
| 23:48 | • New ticket [e2698b94b1] Tcl_FSChdir crashes after seteuid. artifact: 93c7bf9b8d user: jmroot | |
Tcl_FSChdir crashes after seteuid
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).
018bd193b2Fix [e2698b94b1]: Tcl_FSChdir crash on macos/macports after seteuid check-in2026-11-23 17:50:331b6add3f04Ticket [4d3f213029] VFS support causes infinite recursion during 'file exists' if working directory has been removed status still Pending with 3 other changes ticket2026-11-23 13:32:24e590554a8fFix [4d3f213029] on 8.6: backport [82a62c58b9] (fix for [e2698b94b1]). When getcwd() fails, Tcl_FSGetCwd() returned an empty path instead of NULL, so [pwd] returned "" without an error. source-9.1 and 9.2 pass again. check-in2026-11-23 13:31:370853fd5d4aMerge 9.0 - Fix [e2698b94b1]. Tcl_FSChdir crash on macos/macports after seteuid check-in2026-04-17 11:08:2082a62c58b9Fix [e2698b94b1]. Tcl_FSChdir crash on macos/macports after seteuid check-in2026-04-17 10:45:107e7e1d3904Start on [e2698b94b1]. Tcl_FSChdir crash on macos after seteuid check-in2026-04-17 04:04:15
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 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.
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.
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.
@jmroot, could you try the 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.
Applying that change prevents the crash in MacPorts. Thank you!
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.
It seems to have been new with Tcl 9 since MacPorts did not see the issue when using 8.6.17.
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).