Skip to content
Tcl Source Code Ticket Change Details
Login

Ticket Change Details

Overview

Artifact ID: 02dec079b806de9de94e31914909ba8afaca3289
Ticket: 1119369fffffffffffffffffffffffffffffffff
segfault in Tcl_EvalObjv (from Tcl_EvalObjEx call)
User & Date: pcmacdon on 2005-02-09 15:52:04
Changes

  1. assignee changed to: "msofer"
  2. cmimetype changed to: "text/plain"
  3. comment changed to:
    There is a problem with the internal handling of Tcl command 
    objects that exposes it to a segmentation fault. 
    The root of the problem seems to be that descendants of 
    Tcl_EvalObjEx() makes an implicit assumption that the list 
    elements of objPtr will not be freed.  But TclCompEvalObj()  
    can and does free them to convert objPtr into bytecode.  
    The following script should reproduce the problem 
    (under Linux at least). 
     
    ######################################## 
    # START OF FILE 
    # Save as a file and execute "tclsh FILE" to see crash 
     if {![info exists SRC]} { 
      set SRC [list source $argv0] 
      uplevel #0 $SRC 
    } else { 
      namespace eval x { 
        if {[info exists ::DONE]} { error "DUPLICATE SOURCE" } 
        set ::DONE 1 
        namespace eval :: $SRC 
      } 
    } 
    # END OF FILE 
    ##################################### 
     
     
    I've found two specific changes that eliminate the segfault problem 
    for me (although this is by no means a comprehensive solution). 
     
    The first is in Tcl_FSEvalFile() where the following block is moved after 
    the error processing (to just before the "end:" label). 
     
     
        if (iPtr->scriptFile != NULL) { 
            Tcl_DecrRefCount(iPtr->scriptFile); 
        } 
        iPtr->scriptFile = oldScriptFile; 
     
     
    The second is a change to the Tcl_EvalObjv call in Tcl_EvalObjEx(). 
    There are two possibilities here.  Option 1 is to just add 
    TCL_EVAL_INVOKE to  
    the flag in the call.  ie: 
     
     
       result = Tcl_EvalObjv(interp, listRepPtr->elemCount, 
             listRepPtr->elements, flags | TCL_EVAL_INVOKE); 
     
     
    If that is undesirable, then option 2 is a new TclEvalObjvList() function 
    which takes an additional argument (the listRepPtr) which can be 
    checked 
    to see if the representation is no longer a list, before error processing. 
    Tcl_EvalObjEx() can use this new function. 
    eg. 
     
     
    static int 
    TclEvalObjvList(interp, objc, objv, flags, objPtr) 
    //  Old body of Tcl_EvalObjv here... 
        if ((code == TCL_ERROR) && !(flags & TCL_EVAL_INVOKE)) { 
     
     
            /*  
             * If there was an error, a command string will be needed for the  
             * error log: generate it now if it was not done previously. 
             */ 
     
     
            if (cmdLen == 0 && ((!objPtr) || (objPtr->typePtr == 
    &tclListType))) { 
    //... 
    } 
     
     
    int 
    Tcl_EvalObjv(interp, objc, objv, flags) 
    ... 
    { 
       return TclEvalObjvList(interp, objc, objv, flags, NULL); 
    } 
     
     
    
  4. foundin changed to: "None"
  5. priority changed to: "5 Medium"
  6. resolution changed to: "None"
  7. status changed to: "Open"
  8. submitter changed to: "pcmacdon"
  9. subsystem changed to: "10. Objects"
  10. title changed to: "segfault "
  11. type changed to: "Bug"