Artifacts Associated With Ticket a63f5a4fed
Ticket change [0dc48976a1] (rid 258526) by serhiy.storchaka on 2026-10-17 10:51:11:
- cmimetype initialized to: "text/x-fossil-wiki"
- comment initialized 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>). - foundin initialized to: "8.6.18, 9.0.5, 9.1.0"
- login: "serhiy.storchaka"
- priority initialized to: "5 Medium"
- resolution initialized to: "None"
- severity initialized to: "Important"
- status initialized to: "Open"
- subsystem initialized to: "20. [interp]"
- title initialized to:
Safe interp gets the parent's -errorinfo and -errorstack through a failing alias
- type initialized to: "Bug"
Ticket change [8157db24a5] (rid 258564) by serhiy.storchaka on 2026-10-17 11:50:46:
- icomment:
Proposed fix in branch [/timeline?r=safe-interp-no-parent-traceback|safe-interp-no-parent-traceback]: <tt>Tcl_TransferResult()</tt> no longer transfers <tt>-errorinfo</tt>, <tt>-errorstack</tt> and <tt>-errorline</tt> from a trusted interp to a safe one; the message, <tt>-errorcode</tt> and the return code still pass. The safe interp starts its own traceback at the alias call. knownBug test interp-26.8 now passes, new test interp-26.10; four safe.test tests that expected part of the parent's traceback are updated. This also fixes the safe interp part of [77f0dbc0f8]. It is a behaviour change of a public function, so it is proposed for 9.1 only.
- login: "serhiy.storchaka"
- mimetype: "text/x-fossil-wiki"
- icomment:
Ticket change [6cbb22bb5c] (rid 259531) by serhiy.storchaka on 2026-10-20 18:11:28:
- submitter changed to: "serhiy.storchaka"
Ticket change [60b4c1556c] (rid 259593) by jan.nijtmans on 2026-10-20 21:11:13:
- assignee changed to: "jan.nijtmans"
- closer changed to: "nobody"
- 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>). - 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!
- login: "jan.nijtmans"
- mimetype: "text/x-fossil-wiki"
Ticket change [1f2341b7f9] (rid 259594) by jan.nijtmans on 2026-10-20 21:12:08:
- 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 and 8.6 too. Just go ahead!
- login: "jan.nijtmans"
- mimetype: "text/x-fossil-wiki"
- icomment:
Ticket change [0317a9f699] (rid 259612) by serhiy.storchaka on 2026-10-20 21:22:39:
- icomment:
Merged to [24b65a6fb6|trunk], [19a0f244cb|core-9-0-branch] and [cc7f58c2fd|core-8-6-branch]. On 9.0 and 8.6 the expected results of interp-26.10 (<code>invokeStk1</code>) and, on 8.6, safe-11.7.1 (no parent frame any more) were adjusted.
- login: "serhiy.storchaka"
- mimetype: "text/x-fossil-wiki"
- resolution changed to: "Fixed"
- status changed to: "Closed"
- icomment:
Ticket change [de17c90707] (rid 259614) by jan.nijtmans on 2026-10-20 21:24:41:
- closedate changed to: "2461334.3921422223"
- closer changed to: "jan.nijtmans"
- icomment: "Please don't forget the changes.md/changes entries"
- login: "jan.nijtmans"
- mimetype: "text/x-fossil-wiki"