Skip to content
Tcl Source Code History Of Ticket 86b3c15f0c
Login

History Of Ticket 86b3c15f0c

Artifacts Associated With Ticket 86b3c15f0c

  1. Ticket change [ec92617e78] (rid 222037) by kjnash on 2024-02-02 19:14:38:

    1. assignee initialized to: "nobody"
    2. closer initialized to: "nobody"
    3. cmimetype initialized to: "text/x-fossil-plain"
    4. comment initialized to:
      The command ::unknown is careful to evaluate commands in the namespace of the caller - with one exception, which in a corner case can lead to infinite recursion.
      
      The corner case is unusual but not perverse - it occurs when ::unknown is renamed into a different namespace.
      
      Sometimes a package renames ::unknown - e.g. TclReadLine (a pure-Tcl replacement for GNU readline, https://wiki.tcl-lang.org/20215 ) renames ::unknown to ::_unknown and replaces it with its own ::unknown command, which calls ::_unknown.
      
      While experimenting with improvements to TclReadLine, I decided to rename ::unknown into the ::TclReadLine namespace, in order to avoid pollution of the global namespace.  This exposes the bug. If the user types a command that exists in the ::TclReadLine namespace but not in the global namespace, the renamed ::unknown goes into infinite recursion: it believes it has found the command, but when it tries to execute it, it is not there.
      
      A simple demonstration is to type these commands in an interactive shell:
      
        namespace eval ::foo {}
        rename unknown ::foo::unknown
        interp alias {} unknown {} ::foo::unknown
        proc ::foo::bar {} {}
      
        bar
      
      
      The fix is simple, and is in the patch attached.  The bug is found in all versions of Tcl.
      
      In view of the importance of ::unknown, I would appreciate review before committing this change.
      
      diff -Naur original/library/init.tcl patched/library/init.tcl
      --- original/library/init.tcl   2023-08-21 02:45:35.424433637 +0100
      +++ patched/library/init.tcl    2024-02-02 18:41:18.049045928 +0000
      @@ -371,7 +371,10 @@
                  return -options $::tcl::UnknownOptions $::tcl::UnknownResult
              }
       
      -       set ret [catch {set candidates [info commands $name*]} msg]
      +       set ret [catch [list uplevel 1 [list info commands $name*]] msg]
      +       if {$ret == 0} {
      +           set candidates $msg
      +       }
              if {$name eq "::"} {
                  set name ""
              }
      
    5. foundin initialized to: "all"
    6. is_private initialized to: "0"
    7. login: "kjnash"
    8. priority initialized to: "5 Medium"
    9. private_contact initialized to: "a774b1f5653dc3360e29ea7d635a64e94c9f1dab"
    10. resolution initialized to: "None"
    11. severity initialized to: "Minor"
    12. status initialized to: "Open"
    13. submitter initialized to: "kjnash"
    14. subsystem initialized to: "18. Commands M-Z"
    15. title initialized to: "::unknown has infinite recursion in a corner case"
    16. type initialized to: "Patch"
  2. Add attachment "init-unknown-86.patch" [a689e2b553] (rid 222039) by kjnash on 2024-02-02 19:15:48.

  3. Ticket change [ee85950534] (rid 222106) by jan.nijtmans on 2024-02-06 15:08:08:

    1. assignee changed to: "jan.nijtmans"
    2. closedate changed to: "2460347.13065056"
    3. closer changed to: "jan.nijtmans"
    4. icomment:
      Fixed [524d68410a678b23|here].
      
      Thanks for the report and the patch!
      
    5. login: "jan.nijtmans"
    6. mimetype: "text/x-fossil-wiki"
    7. resolution changed to: "Fixed"
    8. status changed to: "Closed"