| Ticket UUID: | 1a7976b873c9828c29c5abc0ac90739f196ab783 | |||
| Title: | pluginmgr potential collisions with files/folders in cwd | |||
| Type: | Bug | Version: | ||
| Submitter: | juliannoble2 | Created on: | 2025-10-06 04:56:24 | |
| Subsystem: | (unused) | Assigned To: | ||
| Priority: | 5 Medium | Severity: | Minor | |
| Status: | Open | Last Modified: | 2026-11-16 00:06:14 | |
| Resolution: | None | Closed By: | nobody | |
| Closed on: | ||||
| Description: |
The primary mechanism for listing plugins is the package database,
as used in the list method.
The private LoadPlugin method tries to do direct load first, followed by fallback to package require
The LoadPlugin method contains the following as the first load mechanism, prior to looking for packages:
if {[file exists $name]} {
# Plugin files are loaded directly.
$sip invokehidden source $name
return 1
}
This check for an unqualified name operates in whatever is the current working directory, without reference to the package/module paths or any of the paths explicitly specified for the pluginmgr object
This means that if the cwd happens to contain a file or folder with the same basename as the plugin intended to load - it will either fail in the case of a directory name - or source some unintended file.
It's unclear if there was some intention that this direct load mechanism is to support calling something like :
plugmgrObject load adhocplugin.tcl
from the current directory or perhaps with an absolute path - but in any case such a file wouldn't show in the results of 'plugmgrObject list'
and the collision risk for cwd folders and plugin names is high and quite confusing when it occurs.
I am guessing that this should have been wrapped in a while loop over the $paths variable - to restrict it to the paths that have been configured via safe::interpAddToAccessPath
As it stands, the parent interpreter seems to be able to source from a folder that isn't in that list (cwd)
Even if this were adjusted to operate on the configured paths,
It seems to me the name would have to contain the extension e.g myplugin.tcl to work, and as there is no check that $name isn't a folder - it could easily collide if the user had a common structure for sub packages e.g
myplugin.tcl
myplugin (folder)
subplugin.tcl
Taking the aged example at: https://wiki.tcl-lang.org/page/pluginmgr
This only works for me if I run it from within the described ~/.example/plugin/ folder
and only then if I use plug load slang.tcl
There doesn't seem to be any mechanism by which the pkgIndex.tcl files in the plugin folder are even scanned unless it were already on the auto_path. Similarly there seems to be no way that the paths from the env,registry or home subfolders are added to tcl::tm::list for the safe interp, and no way to load them without explicitly specifying their full name.
The wiki example can also be used to easily test the unexpected attempt to source from pwd, by running tclsh in an arbitrary folder with a file or subfolder named slang or simple.
| |||
| User Comments: |
serhiy.storchaka added on 2026-11-16 00:06:14:
Proposed fix in branch pluginmgr-cwd-dir-collision: LoadPlugin uses file isfile instead of file exists, so a directory with the plugin's name in the current directory no longer breaks loading. Adds pluginmgr.test. juliannoble2 added on 2025-10-06 07:53:01: Sorry - much of this issue may be pilot error in that I had a typo in a pkgIndex.tcl file. This is silent - then resulting in the behaviour mentioned. I think it still may be worth reviewing some of this. juliannoble2 added on 2025-10-06 07:27:58: I guess I'm suggesting adding something like the following to the LoadPlugin method, along with documentation to indicate that the home, env and registry based paths don't automatically support .tm based modules, only supporting pkgIndex.tcl based libs or dropin 'directplugin.tcl' files.
Other arbitrary paths could still be supported by an application specifically for .tm or pkgIndex.tcl packages - as long as they were ordinarily (or explicitly) configured in auto_path or tcl::tm::list.
If this approach were taken, a similar code block would be needed in the list method to append appropriate entries to the results.
foreach p $paths {
set fp [file join $p $name]
#This won't load .tm files
if {[file exists $fp.tcl] && [file type $fp.tcl] eq "file"} {
# Plugin files can be loaded directly without pkgIndex.tcl
# This allows dropping of a single plugin.tcl file into a home, env or registry based plugin path
# Such a file may override libs here or on auto_path, and may override modules already in tm path.
$sip invokehidden source $fp.tcl
return 1
}
if {[file exists [file join $p pkgIndex.tcl]} {
$sip invokehidden source [file join $p pkgIndex.tcl]
#and pkgIndex.tcl one level deep - review
set subdirs [glob -nocomplain -directory $p -types d -tails *]
foreach s $subdirs {
if {[file exists [file join $p $s pkgIndex.tcl]]} {
$sip invokehidden source [file join $p $s pkgIndex.tcl]
}
}
#continue below to load packages
}
}
| |||
Home
Blog
Docs
Downloads
Tickets
Timeline
Branches
Tags
Wiki