Overview
| Artifact ID: | 5e8cc9c30f0e75604075b2e3402724d95e453b64 |
|---|---|
| Ticket: | bdd91c7e431d8d9d448e5ce04cc02849c901e6f8
tclsh crashes in [interp delete] |
| User & Date: | azazel on 2013-09-12 15:43:54 |
Changes
- assignee changed to: "nobody"
- closer changed to: "nobody"
- cmimetype changed to: "text/plain"
- comment changed to:
I've compiled 8.5.14 as follows: ./configure --enable-shared --enable-symbols --prefix=/tmp/tcl8.5.14 && make && make install Running the following code: $ cat ~/tmp/test/test.tcl set i [interp create] interp eval $i { for { set i 1000000 } { $i < 1250000 } { incr i } { lappend data $i $i } lappend l {*}$data array set a $data set d [dict create {*}$data] } interp delete $i causes a seg-fault: $ /tmp/tcl8.5.14/bin/tclsh8.5 ~/tmp/test/test.tcl Segmentation fault (core dumped) when deleting the slave interpreter: (gdb) bt #0 0x00007f0fa6c7c040 in TclObjCallVarTraces [...] #1 0x00007f0fa6c897dd in DeleteArray [...] #2 0x00007f0fa6c857f8 in UnsetVarStruct [...] #3 0x00007f0fa6c89393 in TclDeleteNamespaceVars [...] #4 0x00007f0fa6c46a63 in TclTeardownNamespace [...] #5 0x00007f0fa6b9eecc in DeleteInterpProc [...] #6 0x00007f0fa6c62b31 in Tcl_EventuallyFree [...] #7 0x00007f0fa6b9edd8 in Tcl_DeleteInterp [...] #8 0x00007f0fa6c23831 in SlaveObjCmdDeleteProc [...] #9 0x00007f0fa6ba0fc1 in Tcl_DeleteCommandFromToken [...] #10 0x00007f0fa6c206c1 in Tcl_InterpObjCmd [...] #11 0x00007f0fa6ba2374 in TclEvalObjvInternal [...] #12 0x00007f0fa6ba3872 in TclEvalEx [...] #13 0x00007f0fa6ba2bec in Tcl_EvalEx [...] #14 0x00007f0fa6c3bf3d in Tcl_FSEvalFileEx [...] #15 0x00007f0fa6c44f75 in Tcl_Main [...] #16 0x00000000004008c3 in main [...] Running it under valgrind reveals the following: Invalid write of size 8 at 0x4ED287D: TclExecuteByteCode (tclExecute.c:2408) by 0x4ED09F0: TclCompEvalObj (tclExecute.c:1537) by 0x4E6D966: TclEvalObjEx (tclBasic.c:5260) by 0x4EECA27: SlaveEval (tclInterp.c:2611) by 0x4EE977E: Tcl_InterpObjCmd (tclInterp.c:789) by 0x4E6B383: TclEvalObjvInternal (tclBasic.c:3693) by 0x4E6C881: TclEvalEx (tclBasic.c:4392) by 0x4E6BBFB: Tcl_EvalEx (tclBasic.c:4049) by 0x4F04F4C: Tcl_FSEvalFileEx (tclIOUtil.c:1853) by 0x4F0DF84: Tcl_Main (tclMain.c:439) by 0x4008D2: main (tclAppInit.c:85) Address 0x5b23fe8 is 104 bytes inside a block of size 16,040 free'd at 0x4C2A68C: free (vg_replace_malloc.c:446) by 0x4E668C3: TclpFree (tclAlloc.c:723) by 0x4E73611: Tcl_Free (tclCkalloc.c:1221) by 0x4ECF88A: DeleteExecStack (tclExecute.c:772) by 0x4ECFE8A: GrowEvaluationStack (tclExecute.c:1000) by 0x4ED2525: TclExecuteByteCode (tclExecute.c:2304) by 0x4ED09F0: TclCompEvalObj (tclExecute.c:1537) by 0x4E6D966: TclEvalObjEx (tclBasic.c:5260) by 0x4EECA27: SlaveEval (tclInterp.c:2611) by 0x4EE977E: Tcl_InterpObjCmd (tclInterp.c:789) by 0x4E6B383: TclEvalObjvInternal (tclBasic.c:3693) by 0x4E6C881: TclEvalEx (tclBasic.c:4392) Invalid read of size 8 at 0x4ED2996: TclExecuteByteCode (tclExecute.c:2422) by 0x4ED09F0: TclCompEvalObj (tclExecute.c:1537) by 0x4E6D966: TclEvalObjEx (tclBasic.c:5260) by 0x4EECA27: SlaveEval (tclInterp.c:2611) by 0x4EE977E: Tcl_InterpObjCmd (tclInterp.c:789) by 0x4E6B383: TclEvalObjvInternal (tclBasic.c:3693) by 0x4E6C881: TclEvalEx (tclBasic.c:4392) by 0x4E6BBFB: Tcl_EvalEx (tclBasic.c:4049) by 0x4F04F4C: Tcl_FSEvalFileEx (tclIOUtil.c:1853) by 0x4F0DF84: Tcl_Main (tclMain.c:439) by 0x4008D2: main (tclAppInit.c:85) Address 0x5b23fd8 is 88 bytes inside a block of size 16,040 free'd at 0x4C2A68C: free (vg_replace_malloc.c:446) by 0x4E668C3: TclpFree (tclAlloc.c:723) by 0x4E73611: Tcl_Free (tclCkalloc.c:1221) by 0x4ECF88A: DeleteExecStack (tclExecute.c:772) by 0x4ECFE8A: GrowEvaluationStack (tclExecute.c:1000) by 0x4ED2525: TclExecuteByteCode (tclExecute.c:2304) by 0x4ED09F0: TclCompEvalObj (tclExecute.c:1537) by 0x4E6D966: TclEvalObjEx (tclBasic.c:5260) by 0x4EECA27: SlaveEval (tclInterp.c:2611) by 0x4EE977E: Tcl_InterpObjCmd (tclInterp.c:789) by 0x4E6B383: TclEvalObjvInternal (tclBasic.c:3693) by 0x4E6C881: TclEvalEx (tclBasic.c:4392) Afaics, the problem lies in generic/tclExecute.c, ll. 2304ff.: moved = (GrowEvaluationStack(iPtr->execEnvPtr, length, 1) - 1) - (Tcl_Obj **) initCatchTop; if (moved) { /* * Change the global data to point to the new stack. */ initCatchTop += moved; catchTop += moved; initTosPtr += moved; tosPtr += moved; esPtr = iPtr->execEnvPtr->execStackPtr; } Note that if the stack has been moved, initCatchTop and catchTop are adjusted, but bcFramePtr is not, which results in the invalid accesses at ll. 2408ff.: bcFramePtr->data.tebc.pc = (char *) pc; iPtr->cmdFramePtr = bcFramePtr; if (iPtr->flags & INTERP_DEBUG_FRAME) { TclArgumentBCEnter((Tcl_Interp *) iPtr, objv, objc, codePtr, bcFramePtr, pc - codePtr->codeStart); } DECACHE_STACK_INFO(); result = TclEvalObjvInternal(interp, objc, objv, /* call from TEBC */(char *) -1, -1, 0); CACHE_STACK_INFO(); if (iPtr->flags & INTERP_DEBUG_FRAME) { TclArgumentBCRelease((Tcl_Interp *) iPtr, objv, objc, codePtr, pc - codePtr->codeStart); } iPtr->cmdFramePtr = iPtr->cmdFramePtr->nextPtr; Adjusting bcFramePtr: $ diff -uw generic/tclExecute.c.orig generic/tclExecute.c --- generic/tclExecute.c.orig 2013-09-12 16:39:13.339001366 +0100 +++ generic/tclExecute.c 2013-09-12 16:39:18.383001702 +0100 @@ -2311,6 +2311,7 @@ initCatchTop += moved; catchTop += moved; + bcFramePtr = (CmdFrame *) (initCatchTop + codePtr->maxExceptDepth + 1); initTosPtr += moved; tosPtr += moved; esPtr = iPtr->execEnvPtr->execStackPtr; appears to fix the problem. - foundin changed to: "8.5.14"
- is_private changed to: "0"
- login: "azazel"
- priority changed to: "5 Medium"
- private_contact changed to: "39e20716815af3b420c05fe7afb33a91d4ea98fc"
- resolution changed to: "None"
- severity changed to: "Severe"
- status changed to: "Open"
- submitter changed to: "azazel"
- subsystem changed to: "20. [interp]"
- title changed to: "tclsh crashes in [interp eval]"
- type changed to: "Bug"