Skip to content
Tcl Source Code Ticket Change Details
Login

Ticket Change Details

Overview

Artifact ID: d3a7117e2ee42e1e01074ae39e87bf5c6ead2342
Ticket: 217796ffffffffffffffffffffffffffffffffff
TCL SIGSEGV when accessing traced global var from inside a p
User & Date: nobody on 2000-10-26 00:43:48
Changes

  1. assignee changed to: "nobody"
  2. cmimetype changed to: "text/plain"
  3. comment changed to:
    OriginalBugID: 934 Bug
    Version: 8.1a2
    SubmitDate: '1998-12-04'
    LastModified: '1998-12-08'
    Severity: CRIT
    Status: Closed
    Submitter: welch
    ChangedBy: stanton
    RelatedBugIDs: 796  937
    OS: Solaris
    OSVersion: 2.5 (sparc)
    Machine: Other
    FixedDate: '2000-10-25'
    ClosedDate: '1998-12-08'
    
    
    Name:
    
    Mike Isely
    
    
    Extensions:
    
    (none)
    
    
    CustomShell:
    
    Only changes made are this bug fix, plus a previous change regarding a bug in using vfork() in the Tcl exec command (already reported that one).
    
    
    ReproducibleScript:
    
    
    #Run this script in a Tcl 8.1a2 tclsh: "tclsh8.1 breaktcl.sh".
    
    #
    
    #File breaktcl.sh
    
    
    proc t1trace {name1 name2 op} {
    
        puts "t1trace $name1 $name2 $op"
    
    }
    
    
    proc thisblowsup { } {
    
        global t1var
    
        puts "t1var is $t1var"
    
        set t1var "Holy hubcaps Batman! You flooded it!"
    
    #SIGSEGV happens on next line
    
        puts "t1var is now $t1var"
    
    }
    
    
    set t1var "hello"
    
    trace variable t1var rwu t1trace
    
    thisblowsup
    
    
    ObservedBehavior:
    
    It seems that executing a set followed by a puts displaying the same variable named by the set causes a specific sequence of byte code to be compiled / executed which misbehaves when the variable is a traced global and you're executing inside a proc.  This problem does not occur in tcl 8.0.  Here's the output from a (broken) run:
    
    
    isely@ithink$ ~/work/cvs/w1/tcl/bin/tclsh8.1 breaktcl.sh
    
    t1trace t1var  r
    
    t1var is hello
    
    t1trace t1var  w
    
    Segmentation Fault(coredump)
    
    
    Here's a gdb session with stack traceback for the SIGSEGV:
    
    (gdb) run ~/junk/breaktcl.sh
    
    Starting program: /home/isely/work/cvs/w1/tcl/bin/tclsh8.1 ~/junk/breaktcl.sh
    
    t1trace t1var  r
    
    t1var is hello
    
    t1trace t1var  w
    
    
    Program received signal SIGSEGV, Segmentation fault.
    
    0x2a528 in CallTraces (iPtr=0xd8340, arrayPtr=0x0, varPtr=0xe3070, part1=0x0, 
    
        part2=0x0, flags=16) at ./../generic/tclVar.c:3792
    
    (gdb) where
    
    #0  0x2a528 in CallTraces (iPtr=0xd8340, arrayPtr=0x0, varPtr=0xe3070, 
    
        part1=0x0, part2=0x0, flags=16) at ./../generic/tclVar.c:3792
    
    #1  0x250a4 in TclGetIndexedScalar (interp=0xd8340, localIndex=0, 
    
        leaveErrorMsg=1) at ./../generic/tclVar.c:641
    
    #2  0x5b6d8 in TclExecuteByteCode (interp=0xd8340, codePtr=0xe2de8)
    
        at ./../generic/tclExecute.c:1068
    
    #3  0x30188 in Tcl_EvalObj (interp=0xd8340, objPtr=0xe4748, flags=0)
    
        at ./../generic/tclBasic.c:2587
    
    #4  0x922c8 in TclObjInterpProc (clientData=0xe3020, interp=0xd8340, objc=1, 
    
        objv=0xefffdf50) at ./../generic/tclProc.c:854
    
    #5  0x1c018 in Tcl_EvalObjv (interp=0xd8340, objc=1, objv=0xefffdf50, 
    
        command=0xe20ca "thisblowsup\n", length=12, flags=0)
    
        at ./../generic/tclParse.c:901
    
    #6  0x1c95c in Tcl_Eval2 (interp=0xd8340, 
    
        script=0xe1f40 "\n#Run this script in a Tcl 8.1a2 tclsh: \"tclsh8.1 breaktcl.sh\".\n#\n#File breaktcl.sh\n\nproc t1trace {name1 name2 op} {\n    puts \"t1trace $name1 $name2 $op\"\n}\n \nproc thisblowsup { } {\n    global t1var\n  "..., numBytes=406, flags=0) at ./../generic/tclParse.c:1279
    
    #7  0x7f288 in Tcl_EvalFile (interp=0xd8340, 
    
        fileName=0xefffe3f4 "/home/isely/junk/breaktcl.sh")
    
        at ./../generic/tclIOUtil.c:258
    
    #8  0x18e28 in Tcl_Main (argc=1, argv=0xefffe9c8, 
    
        appInitProc=0x18b1c <Tcl_AppInit>) at ./../generic/tclMain.c:141
    
    #9  0x18b08 in main (argc=2, argv=0xefffe9c4) at ./../unix/tclAppInit.c:83
    
    (gdb) 
    
    
    DesiredBehavior:
    
    This is the same run using a tcl 8.0 tclsh:
    
    
    isely@ithink$ tclsh breaktcl.sh
    
    t1trace t1var  r
    
    t1var is hello
    
    t1trace t1var  w
    
    t1trace t1var  r
    
    t1var is now Holy hubcaps Batman! You flooded it!
    
    
    Patch:
    
    http://www.enteract.com/~isely/tclVar.c.patch
    
    
    PatchFiles:
    
    generic/tclVar.c
    
    
    
    
    The problem is that TclGetIndexedScalar() is relying on varPtr->name to retrieve the variable name.  However if varPtr is a link (to a global variable looked up via hash), the linked-to variable may not have a variable name stored there.  This results in a null-pointer deref inside of CallTraces(), and a crash.  The solution is to retrieve and save varPtr->name before traversing any possible link(s).  It turns out that TclSetIndexedScalar() has precisely the same issue and it's already been fixed there.  Hmm, looks like a fix to cut/pasted code.  I fixed it by propagating the same fix from TclSetIndexedScalar() to TclGetIndexedScalar().
    
    The reason why this only seems to break after a set command is because the TCL compiler appears to be compiling variable references two different ways.  One method doesn't use TclGetIndexedScalar(), and this is the method used for the first puts in my test case above.  The second method seems to be enabled after compiling the set command and that when things break.
    
    
    
  4. foundin changed to: "obsolete: 8.1a2"
  5. priority changed to: "5 Medium"
  6. resolution changed to: "None"
  7. status changed to: "Open"
  8. submitter changed to: "nobody"
  9. subsystem changed to: "69. Other"
  10. title changed to:
    TCL SIGSEGV when accessing traced global var from inside a p
    
  11. type changed to: "Bug"