<i>Safe interp gets the parent's -errorinfo and -errorstack through a failing alias</i> status still Open with 6 other changes
by
.
D 2026-10-20T21:11:13.852
J assignee jan.nijtmans
J closer nobody
J comment When\sa\scommand\sin\sa\ssafe\sinterpreter\sis\san\salias\sto\sa\sproc\sin\sa\strusted\sparent\sand\sthat\sproc\r\nfails,\sthe\sfull\s<tt>-errorinfo</tt>\sand\s<tt>-errorstack</tt>\sof\sthe\sparent\sare\scopied\sinto\sthe\r\nsafe\sinterpreter.\sThe\ssafe\sinterpreter\sthen\ssees\sthe\sparent's\sproc\snames,\sthe\stext\sof\stheir\r\nbodies,\sfile\snames\sof\ssourced\sscripts\sand,\sthrough\s<tt>-errorstack</tt>,\sthe\sactual\sargument\r\nvalues\sof\severy\sparent\sproc\son\sthe\scall\sstack.\r\n\r\n<verbatim>\r\nproc\sGetPassword\s{user}\s{return\shunter2}\r\nproc\sVerifyPassword\s{user\spw}\s{error\s"access\sdenied"}\r\nproc\sLoginAlias\s{user}\s{VerifyPassword\s$user\s[GetPassword\s$user]}\r\nset\ss\s[interp\screate\s-safe]\r\ninterp\salias\s$s\slogin\s{}\sLoginAlias\r\nputs\s[interp\seval\s$s\s{\r\n\s\s\s\scatch\s{login\salice}\smsg\sopts\r\n\s\s\s\slist\s$::errorInfo\s[dict\sget\s$opts\s-errorstack]\r\n}]\r\n</verbatim>\r\n\r\nActual\soutput\s(9.1,\s9.0,\s8.6):\r\n\r\n<verbatim>\r\n{access\sdenied\r\n\s\s\s\swhile\sexecuting\r\n"error\s"access\sdenied""\r\n\s\s\s\s(procedure\s"VerifyPassword"\sline\s1)\r\n\s\s\s\sinvoked\sfrom\swithin\r\n"VerifyPassword\s$user\s[GetPassword\s$user]"\r\n\s\s\s\s(procedure\s"LoginAlias"\sline\s1)\r\n\s\s\s\sinvoked\sfrom\swithin\r\n"login\salice"}\s{INNER\s{returnImm\s{access\sdenied}\s{}}\sCALL\s{VerifyPassword\salice\shunter2}\sCALL\s{LoginAlias\salice}}\r\n</verbatim>\r\n\r\nExpected:\sthe\ssafe\sinterpreter\ssees\sonly\sthe\serror\smessage\sand\sits\sown\spart\sof\sthe\straceback,\r\nas\sif\s<tt>login</tt>\swere\sa\sC\scommand\sfailing\swith\sthat\smessage:\r\n\r\n<verbatim>\r\n{access\sdenied\r\n\s\s\s\sinvoked\sfrom\swithin\r\n"login\salice"}\s{}\r\n</verbatim>\r\nIf\sthe\salias\starget\sdoes\s<nowiki>[source]</nowiki>\sa\sfile\sand\sthe\sscript\sfails,\sthe\straceback\r\nalso\scontains\s<tt>(file\s"/full/path/of/the/parent/script.tcl"\sline\sN)</tt>.\r\n\r\nCause:\s<tt>AliasObjCmd</tt>\sin\sgeneric/tclInterp.c\scalls\s<tt>Tcl_TransferResult</tt>,\swhich\r\ncopies\sthe\swhole\sreturn\soptions\sdictionary\s(<tt>Tcl_GetReturnOptions</tt>)\sof\sthe\sparent\sinto\r\nthe\schild,\swhether\sthe\schild\sis\ssafe\sor\snot.\sThe\sSafe\sBase\savoids\sthis\sonly\sbecause\sits\salias\r\nprocs\srethrow\swith\s<nowiki>[return\s-code\serror\s$msg]</nowiki>;\suser-defined\saliases\sget\sno\ssuch\r\nprotection.\sA\spossible\sfix\sis\sto\sdrop\s<tt>-errorinfo</tt>\sand\s<tt>-errorstack</tt>\s(keeping\sthe\r\nmessage,\s<tt>-errorcode</tt>\sand\sthe\sreturn\scode)\swhen\sthe\starget\sinterpreter\sis\ssafe\sand\sthe\r\nsource\sis\snot.\r\n\r\nThis\sis\sthe\sknownBug\stest\sinterp-26.8,\sone\sof\sthe\stests\scollected\sin\s[219164ffff]\s(bug\s1637,\r\n1999).\sThe\serrorInfo\spart\shas\sbeen\sthere\sat\sleast\ssince\s8.4;\s<tt>-errorstack</tt>\s(8.6)\smade\sit\r\nworse,\ssince\sit\scarries\sargument\svalues.\sRelated:\s[77f0dbc0f8]\s(a\sstale\s<tt>-errorstack</tt>\r\nfrom\san\searlier,\salready\scaught\serror\sin\sthe\sparent\sis\salso\spassed\sthrough\san\salias,\sbecause\r\n<tt>Tcl_GetReturnOptions</tt>\signores\s<tt>resetErrorStack</tt>),\s[1669424fff]\s(file\snames\sleak\r\ninto\ssafe\sinterps\svia\s<nowiki>[info\sframe]</nowiki>).
J icomment >\sIt\sis\sa\sbehaviour\schange\sof\sa\spublic\sfunction,\sso\sit\sis\sproposed\sfor\s9.1\sonly.\r\n\r\nSince\sit's\sa\spotential\ssecurity\srisk,\sI'm\sinclined\sto\saccept\sit\sfor\s9.0.\r\n\r\nJust\sgo\sahead!
J login jan.nijtmans
J mimetype text/x-fossil-wiki
K a63f5a4fed23469bf1e1caaaf674b9dc765dd2ce
U jan.nijtmans
Z bf7d3d45845096ae3fba02961d576b0b