Skip to content
Tcl Source Code Ticket Change Details
Login

Ticket Change Details

Overview

Artifact ID: 60b4c1556cbc331d1ef0528939635245d1c7e123d77d9dbc3c189483d1a5da38
Ticket: a63f5a4fed23469bf1e1caaaf674b9dc765dd2ce
Safe interp gets the parent's -errorinfo and -errorstack through a failing alias
User & Date: jan.nijtmans on 2026-10-20 21:11:13
Changes

  1. assignee changed to: "jan.nijtmans"
  2. closer changed to: "nobody"
  3. 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>).
    
  4. icomment:
    > It is a behaviour change of a public function, so it is proposed for 9.1 only.
    
    Since it's a potential security risk, I'm inclined to accept it for 9.0.
    
    Just go ahead!
    
  5. login: "jan.nijtmans"
  6. mimetype: "text/x-fossil-wiki"