Skip to content
Tcl Source Code View Ticket
Login

View Ticket

2024-11-14
11:49 • Ticket [43c94f9598] Tcl will not start properly if there is an init.tcl file in ... artifact: f3392b7348 user: jan.nijtmans
09:35 • Ticket [43c94f9598]: 4 changes artifact: 31951f494f user: jan.nijtmans
2024-11-13
21:45 • Closed ticket [43c94f9598]. artifact: 289cd00796 user: jan.nijtmans
19:45
partial merge 8.7: fix and coverage for bug [43c94f95988f3057]: avoid vulnerability loading init.tcl... check-in: 01d1cd487a user: sebres tags: trunk, main
19:39
merge 8.6: fix and coverage for bug [43c94f95988f3057]: avoid vulnerability loading init.tcl in curr... check-in: f7d3654527 user: sebres tags: core-8-branch
18:18
fix and coverage for bug [43c94f95988f3057]: avoid vulnerability loading init.tcl in current directo... check-in: 4dbf09a5a7 user: sebres tags: core-8-6-branch
18:14
fix and coverage for bug [43c94f95988f3057]: avoid vulnerability loading init.tcl in current directo... check-in: d020e16a20 user: sebres tags: core-8-5-branch
16:19 • Ticket [43c94f9598] Tcl will not start properly if there is an init.tcl file in ... artifact: 80e6ac7d3a user: stu
15:50 • Ticket [43c94f9598]: 3 changes artifact: 15c30c12c9 user: jan.nijtmans
15:49
Possible fix for [43c94f9598]: Tcl will not start properly if there is an init.tcl file in the curre... closed check-in: 465d4546e2 user: jan.nijtmans tags: bug-43c94f9598
15:21 • Ticket [43c94f9598] Tcl will not start properly if there is an init.tcl file in ... artifact: 0eca06f59b user: jan.nijtmans
14:46 • Ticket [43c94f9598]: 4 changes artifact: 1d84a3cae7 user: anonymous
2024-11-12
04:44 • New ticket [43c94f9598]. artifact: 9e3f5a9bba user: stu

Tcl will not start properly if there is an init.tcl file in the current dir

Closed / Fixed43c94f95988f3057fcabbd2a4b81c6e8ff9909a6Created 2 years agoUpdated 2 years ago
Descriptionplain2024-11-12 04:44:21
This on my system. Your auto_paths may vary.

$ echo 'puts $::auto_path' | tclsh8.6
/usr/local/lib/tcl/tcl8.6 /usr/local/lib/tcl

$ echo 'puts $::auto_path' | tclsh9.0
/usr/local/lib/tcl/tcl9.0 /usr/local/lib/tcl

$ echo '' > init.tcl

$ echo 'puts $::auto_path' | tclsh8.6
/usr/local/lib/tcl/tcl8.6 /usr/local/lib/tcl

$ echo 'puts $::auto_path' | tclsh9.0
can't read "::auto_path": no such variable


Wish provides a different error message for the same problem:

$ wish9.0
application-specific initialization failed: invalid command name "tcl_findLibrary"


And for fun:

$ echo 'puts "I like fish!"' > init.tcl

$ echo 'puts $::auto_path' | tclsh9.0
I like fish!
can't read "::auto_path": no such variable
Referenced by1
  • 465d4546e2Possible fix for [43c94f9598]: Tcl will not start properly if there is an init.tcl file in the current dir check-in2024-11-13 15:49:04
anonymous (claiming to be oehhar)wiki2024-11-13 14:46:25

Stuart, thank you for the example. I fear, it works as expected.

The default init.tcl is in library\init.tcl

You may look into generic\tclInterp.c, function "Tcl_Init" how an alternate init script may be specified.

I also see this as a security hole.

Thank you, Harald

jan.nijtmanswiki2024-11-13 15:21:10

Trying to reproduce it:

$ echo '' > init.tcl

$ echo 'puts $::auto_path' | tclsh8.6 /usr/lib/tcl8.6 /usr/lib

$ echo 'puts $::auto_path' | tclsh9.0 //zipfs:/lib/tcl/tcl_library //zipfs:/lib/tcl /usr/lib

That looks fine to me.

Did you set any environment variables, like TCL_LIBRARY or TCLPKGPATH?

What platform?

jan.nijtmanswiki2024-11-13 15:50:44

My guess: You used a --disable-zipfs build (which you didn't mention in the bug-report). In that case, "::tcl::zipfs::tcl_library_init", which should return the tcl_library directory in the zipfs might return the empty string.

If $tcl_library is the empty string, then [file join $tcl_library init.tcl] (tclInterp.c:449) will point to init.tcl in the current directory.

If my guess is right, [this] should solve the problem.

stuplain2024-11-13 16:19:04
You're pretty quick, Jan!

Yes it is only with a --disable-zipfs build.

I just did some digging and ran some tests after getting the hint from Harald and arrived at the thought that the path might be "".
Didn't investigate further as I came here to add the note about --disable-zipfs.

The fix you provided looks good but I don't know enough about that area of the code to evaluate if it's the best/right fix. Probably is. :)
jan.nijtmanswiki2024-11-13 21:45:52

Well, Sergey finished the work, updating all branches with a fix. Even 8.5/8.6, because the same could happen there if $pkgPath contains {} as list element.

Thanks!

jan.nijtmanswiki2024-11-14 09:35:44

Problem in testcase fixed [here]. Unfortunately, it caused a broken macOS build on Github actions.

This is exactly why I am advocating fixing bugs firt on trunk, and only cherrypick to lower branches after trunk builds are successful.

jan.nijtmanswiki2024-11-14 11:49:42

@sebres, if you like to "merge --cherrypick" this fix to the core-8-5-branch, just go ahead. (I'm not interested in this branch any more)

Log in (anonymous is fine) to add a comment.