Skip to content
Tcl Source Code Ticket Change Details
Login

Ticket Change Details

Overview

Artifact ID: 0dc48976a14901e4fc759d31ef463ef18e2697d6fdc937365be2296e64c2f8c4
Ticket: a63f5a4fed23469bf1e1caaaf674b9dc765dd2ce
Safe interp gets the parent's -errorinfo and -errorstack through a failing alias
User & Date: serhiy.storchaka on 2026-10-17 10:51:11
Changes

  1. cmimetype changed to: "text/x-fossil-wiki"
  2. comment changed to:
    When a command in a safe interpreter is an alias to a proc in a trusted parent and that proc
    fails, the full <tt>-errorinfo</tt> and <tt>-errorstack</tt> of the parent are copied into the
    safe interpreter. The safe interpreter then sees the parent's proc names, the text of their
    bodies, file names of sourced scripts and, through <tt>-errorstack</tt>, the actual argument
    values of every parent proc on the call stack.
    
    <verbatim>
    proc GetPassword {user} {return hunter2}
    proc VerifyPassword {user pw} {error "access denied"}
    proc LoginAlias {user} {VerifyPassword $user [GetPassword $user]}
    set s [interp create -safe]
    interp alias $s login {} LoginAlias
    puts [interp eval $s {
        catch {login alice} msg opts
        list $::errorInfo [dict get $opts -errorstack]
    }]
    </verbatim>
    
    Actual output (9.1, 9.0, 8.6):
    
    <verbatim>
    {access denied
        while executing
    "error "access denied""
        (procedure "VerifyPassword" line 1)
        invoked from within
    "VerifyPassword $user [GetPassword $user]"
        (procedure "LoginAlias" line 1)
        invoked from within
    "login alice"} {INNER {returnImm {access denied} {}} CALL {VerifyPassword alice hunter2} CALL {LoginAlias alice}}
    </verbatim>
    
    Expected: the safe interpreter sees only the error message and its own part of the traceback,
    as if <tt>login</tt> were a C command failing with that message:
    
    <verbatim>
    {access denied
        invoked from within
    "login alice"} {}
    </verbatim>
    If the alias target does <nowiki>[source]</nowiki> a file and the script fails, the traceback
    also contains <tt>(file "/full/path/of/the/parent/script.tcl" line N)</tt>.
    
    Cause: <tt>AliasObjCmd</tt> in generic/tclInterp.c calls <tt>Tcl_TransferResult</tt>, which
    copies the whole return options dictionary (<tt>Tcl_GetReturnOptions</tt>) of the parent into
    the child, whether the child is safe or not. The Safe Base avoids this only because its alias
    procs rethrow with <nowiki>[return -code error $msg]</nowiki>; user-defined aliases get no such
    protection. A possible fix is to drop <tt>-errorinfo</tt> and <tt>-errorstack</tt> (keeping the
    message, <tt>-errorcode</tt> and the return code) when the target interpreter is safe and the
    source is not.
    
    This is the knownBug test interp-26.8, one of the tests collected in [219164ffff] (bug 1637,
    1999). The errorInfo part has been there at least since 8.4; <tt>-errorstack</tt> (8.6) made it
    worse, since it carries argument values. Related: [77f0dbc0f8] (a stale <tt>-errorstack</tt>
    from an earlier, already caught error in the parent is also passed through an alias, because
    <tt>Tcl_GetReturnOptions</tt> ignores <tt>resetErrorStack</tt>), [1669424fff] (file names leak
    into safe interps via <nowiki>[info frame]</nowiki>).
    
  3. foundin changed to: "8.6.18, 9.0.5, 9.1.0"
  4. login: "serhiy.storchaka"
  5. priority changed to: "5 Medium"
  6. resolution changed to: "None"
  7. severity changed to: "Important"
  8. status changed to: "Open"
  9. subsystem changed to: "20. [interp]"
  10. title changed to:
    Safe interp gets the parent's -errorinfo and -errorstack through a failing alias
    
  11. type changed to: "Bug"