Skip to content
Tcl Source Code Artifact [facd5532ad]
Login

Artifact [facd5532ad]

Artifact facd5532ad9d3dc72863fd8a93207fd965533a52:

Ticket change [facd5532ad] - New ticket [218996ffffffffff|218996ffff] <i>bad srcOffsets in bytecompiled [expr] -&gt; CRASH!</i>. by nobody on 2000-10-26 01:09:06.
D 2000-10-26T01:09:06
J assignee nobody
J cmimetype text/plain
J comment OriginalBugID:\s3737\sBug\nVersion:\s8.2.2\nSubmitDate:\s'1999-12-01'\nLastModified:\s'1999-12-02'\nSeverity:\sCRIT\nStatus:\sReleased\nSubmitter:\stechsupp\nChangedBy:\shobbs\nOS:\sAll\nFixedDate:\s'1999-12-02'\nFixedInVersion:\s8.2.3\nClosedDate:\s'2000-10-25'\n\n\nName:\nDon\sPorter\n\nCVS:\n$Id:\stclCompile.c,v\s1.17\s1999/10/21\s02:16:22\shobbs\sExp\s$\n\nCustomShell:\nCompiled\swith\s-DTCL_COMPILE_DEBUG\n\nComments:\nThanks\sto\sJohannes\sSchacht\s<[email protected]>\sfor\ndemonstrating\sthe\sbug.\n\nThe\sproblem\sis\sin\sfile\sgeneric/tclCompile.c\sin\sthe\sroutine\nTclCompileScript(interp,\sscript,\snumBytes,\snested,\senvPtr).\n\nAs\sTclCompileScript\sis\swritten,\sit\sassumes\sthat\sscript\sis\na\ssubstring\sof\senvPtr->source.\s\sThis\sassumption\sis\sused\sin\nline\s839\swhen\scomputing\sthe\ssrcOffset\sfor\sa\scommand\sas\n(parse.commandStart\s-\senvPtr->source).\s\sparse.commandStart\npoints\sinto\sscript.\s\sThe\ssubtraction\sonly\smakes\ssense\sif\nscript\sis\sa\ssubstring\sof\senvPtr->source.\s\sThis\sis\salmost\nalways\sthe\scase.\n\nHowever,\swhen\scompiling\s[expr\s+\s{[set\sa\s0]}],\sthe\sroutine\nTclCompileExprWords()\stries\sto\scompile\sthe\ssubstituted,\nconcatenated\sarguments\sof\s[expr].\s\sIt\sforms\sthe\snew\sstring\n"+\s[set\sa\s0]"\sand\spasses\sit\sas\sthe\sscript\sargument\sto\nTclCompileExpr(interp,\sscript,\snumBytes,\senvPtr).\s\sHowever\nit\spasses\sin\sthe\ssame\senvPtr\sas\sfor\sthe\swhole\scommand.\s\sThe\nnew\sstring\sis\snot\sa\ssubstring\sof\senvPtr->source.\s\sIt's\sin\san\nentirely\sdifferent\ssection\sof\smemory,\sso\sthe\spointer\ssubtraction\nresults\sin\sgarbage\sfor\sthe\ssrcOffset\svalues.\s\sThe\sgarbage\svalues\ncan\sbe\sseen\sin\sthe\scompile\sdebugging\sinformation.\n\nThis\serror\sonly\scauses\sa\scrash\sif\sa\sroutine\stries\sto\suse\sthe\sbad\nsrcOffset\svalues.\s\sThat\shappens\sif\sthe\snested\scommand\sreturns\san\nerror.\s\sWhile\strying\sto\sconstruct\san\sappropriate\s::errorInfo\sstring,\nthe\sroutine\sTcl_LogCommandInfo().\s\sThat\sroutine\stries\sto\suse\sthe\nbad\ssrcOffset\svalues\sand\sis\sled\soff\sinto\smemory\snot\sbelonging\sto\nthe\sprocess,\scausing\sthe\scrash.\s\sThe\ssecond\sexample\sdemonstrates\sthis.\n\nIt's\snot\simmediately\sclear\sto\sme\swhat\sthe\sbest\sfix\sis.\s\sOne\smight\stry\nto\sremove\sthe\sassumption\sin\sTclCompileScript\sthat\sscript\sis\sa\ssubset\nof\senvPtr->source.\s\sOr,\sone\smight\stry\sto\sdetect\sthis\scase\sin\nTclCompileExprWords()\sand\snot\stry\sthe\s"optimistic"\scompile\sof\sthe\narguments\sof\s[expr]\sin\sthis\scircumstance.\s\s\n\nI\shope\sthat\swith\sthese\sexamples\sand\sanalysis\sthat\ssomeone\swith\smore\nfamiliarity\swith\sthe\sdesign\sof\sTcl's\sbytecode\scompiler\smachinery\scan\ndetermine\sthe\smost\sappropriate\sfix.\n\nReproducibleScript:\n#\sFILE:\sdemo.tcl\ncatch\s{foo}\s\s\s\s\s;#\sGet\sall\sauto-loading,\sinitialization,\setc.\sdone\n\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s;#\sbefore\sturning\son\sverbose\scompile\smessages\nset\stcl_traceCompile\s2\ncatch\s{expr\s+\s{[set\sa\s0]}}\ncatch\s{expr\s+\s{[error\sfoo]}}\n\nObservedBehavior:\n$\stclsh\sdemo.tcl\n\s\sCompiling:\s"expr\s+\s{[set\sa\s0]}"\n\nByteCode\s0x201142a0,\srefCt\s1,\sepoch\s0,\sinterp\s0x20102f40\s(epoch\s0)\n\s\sSource\s"expr\s+\s{[set\sa\s0]}"\n\s\sCmds\s2,\ssrc\s18,\sinst\s25,\slitObjs\s5,\saux\s0,\sstkDepth\s2,\scode/src\s15.33\n\s\sCode\s276\s=\sheader\s160+inst\s25+litObj\s40+exc\s28+aux\s0+cmdMap\s12\n\s\sException\sranges\s1,\sdepth\s1:\n\s\s\s\s\s\s0:\slevel\s1,\scatch,\spc\s5-10,\scatch\s14\n\s\sCommands\s2:\n\s\s\s\s\s\s1:\spc\s0-23,\ssrc\s0-17\s\s\s\s\s\s\s\s\s2:\spc\s5-9,\ssrc\s-1129533--1129527\n\s\sCommand\s1:\s"expr\s+\s{[set\sa\s0]}"\n\s\s\s\s(0)\sbeginCatch4\s0\s\n\s\sCommand\s2:\s"set\sa\s0"\n\s\s\s\s(5)\spush1\s0\s\s\s\s\s\s\s\s\s#\s"a"\n\s\s\s\s(7)\spush1\s1\s\s\s\s\s\s\s\s\s#\s"0"\n\s\s\s\s(9)\sstoreScalarStk\s\n\s\s\s\s(10)\suplus\s\n\s\s\s\s(11)\sendCatch\s\n\s\s\s\s(12)\sjump1\s12\s\s\s\s\s\s\s#\spc\s24\n\s\s\s\s(14)\sendCatch\s\n\s\s\s\s(15)\spush1\s2\s\s\s\s\s\s\s\s#\s"+"\n\s\s\s\s(17)\spush1\s3\s\s\s\s\s\s\s\s#\s"\s"\n\s\s\s\s(19)\spush1\s4\s\s\s\s\s\s\s\s#\s"[set\sa\s0]"\n\s\s\s\s(21)\sconcat1\s3\s\n\s\s\s\s(23)\sexprStk\s\n\s\s\s\s(24)\sdone\s\n\s\sCompiling:\s"expr\s+\s{[error\sfoo]}"\n\nByteCode\s0x201142a0,\srefCt\s1,\sepoch\s0,\sinterp\s0x20102f40\s(epoch\s0)\n\s\sSource\s"expr\s+\s{[error\sfoo]}"\n\s\sCmds\s2,\ssrc\s20,\sinst\s26,\slitObjs\s5,\saux\s0,\sstkDepth\s2,\scode/src\s13.80\n\s\sCode\s276\s=\sheader\s160+inst\s26+litObj\s40+exc\s28+aux\s0+cmdMap\s12\n\s\sException\sranges\s1,\sdepth\s1:\n\s\s\s\s\s\s0:\slevel\s1,\scatch,\spc\s5-11,\scatch\s15\n\s\sCommands\s2:\n\s\s\s\s\s\s1:\spc\s0-24,\ssrc\s0-19\s\s\s\s\s\s\s\s\s2:\spc\s5-10,\ssrc\s-1113933--1113925\n\s\sCommand\s1:\s"expr\s+\s{[error\sfoo]}"\n\s\s\s\s(0)\sbeginCatch4\s0\s\n\s\sCommand\s2:\s"error\sfoo"\n\s\s\s\s(5)\spush1\s0\s\s\s\s\s\s\s\s\s#\s"error"\n\s\s\s\s(7)\spush1\s1\s\s\s\s\s\s\s\s\s#\s"foo"\n\s\s\s\s(9)\sinvokeStk1\s2\s\n\s\s\s\s(11)\suplus\s\n\s\s\s\s(12)\sendCatch\s\n\s\s\s\s(13)\sjump1\s12\s\s\s\s\s\s\s#\spc\s25\n\s\s\s\s(15)\sendCatch\s\n\s\s\s\s(16)\spush1\s2\s\s\s\s\s\s\s\s#\s"+"\n\s\s\s\s(18)\spush1\s3\s\s\s\s\s\s\s\s#\s"\s"\n\s\s\s\s(20)\spush1\s4\s\s\s\s\s\s\s\s#\s"[error\sfoo]"\n\s\s\s\s(22)\sconcat1\s3\s\n\s\s\s\s(24)\sexprStk\s\n\s\s\s\s(25)\sdone\s\nSegmentation\sfault\n\nDesiredBehavior:\nNo\scrash.\n\n\n\nThis\swas\sessentially\sdue\sto\san\saggressive\soptimization\sdone\sby\nthe\s'expr'\scompiling\scommand.\s\sIn\sessence,\sit\swas\schecking\sto\nsee\sif\sall\sthe\swords\sthat\scame\sin\swere\sliterals,\sand\smaking\sthe\noptimization\sthat\syou\scould\scompile\sthese\sby\screating\sa\ssingle\nstring\sout\sof\sthe\sliterals:\n\s\s\s\s\sexpr\s1\s+\s{[string\slength\sabc]}\nbecame\sin\sessence\sthe\ssame\sas\n\s\s\s\s\sexpr\s{1\s+\s[string\slength\sabc]}\n\nHowever,\sthe\serror\scase\swould\scause\sthe\sinvalid\schecking\sback\ninto\sthe\ssource\sstring,\sand\sthus\sa\scrash,\sas\smentioned\sin\sthe\ndescription\sabove.\n\nSince\sthis\sall\soccurs\sin\sdegenerate\scases\s(the\suser\sshould\nreally\shave\sused\sthe\slatter\s'expr'),\sit\swas\sdecided\sto\sremove\nthe\sproblematic\soptimization.\s\sThis\swill\scause\sthe\sformer\sto\nnot\sbe\scompiled\sand\sthus\sbe\sslower,\sbut\sstill\scorrect.\s\sThe\nlatter\swill\sstill\sbe\scompiled,\sand\sis\sthe\srecommended\susage.\nHowever,\sfor\sany\scase,\sit\sno\slonger\sseg\sfaults.\n\nThis\sfix\sis\sin\s8.2.3.\s\n--\s12/02/1999\shobbs
J foundin obsolete:\s8.2.2
J priority 5\sMedium
J resolution None
J status Open
J submitter nobody
J subsystem 10.\sObjects
J title bad\ssrcOffsets\sin\sbytecompiled\s[expr]\s->\sCRASH!
J type Bug
K 218996ffffffffffffffffffffffffffffffffff
U nobody
Z c321b52679713f9644cd01051a4d6ad9