diff options
author | Steve Bennett <steveb@workware.net.au> | 2014-10-10 19:06:23 +1000 |
---|---|---|
committer | Steve Bennett <steveb@workware.net.au> | 2014-10-10 19:07:52 +1000 |
commit | a2ae2a197461d1ba500dcff662b27cd0c8f35c9c (patch) | |
tree | e30d1612a2053c1109634f7003dea50be2c4cd7a /nshelper.tcl | |
parent | 7748e1073aedaecb20f1526c38fc223b4937f0e3 (diff) |
namespace: disallow creation of import loops
Signed-off-by: Steve Bennett <steveb@workware.net.au>
Diffstat (limited to 'nshelper.tcl')
-rw-r--r-- | nshelper.tcl | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/nshelper.tcl b/nshelper.tcl index d0cb35a..a31b7c0 100644 --- a/nshelper.tcl +++ b/nshelper.tcl @@ -66,7 +66,19 @@ proc {namespace import} {args} { if {[namespace qualifiers $cmd] eq $current} { return -code error "import pattern \"$pattern\" tries to import from namespace \"$current\" into itself" } - alias ${current}::[namespace tail $cmd] $cmd + # What if this alias would create a loop? + # follow the target alias chain to see if we are creating a loop + set newcmd ${current}::[namespace tail $cmd] + + set alias $cmd + while {[exists -alias $alias]} { + set alias [info alias $alias] + if {$alias eq $newcmd} { + return -code error "import pattern \"$pattern\" would create a loop" + } + } + + alias $newcmd $cmd } } } |