Skip to content
Tcl Source Code Ticket Change Details
Login

Ticket Change Details

Overview

Artifact ID: 756670b53af15da67d5300af1268b17230b3120a
Ticket: 2507159fffffffffffffffffffffffffffffffff
Tcl_Command validity management
User & Date: dgp on 2009-01-14 14:40:14
Changes

  1. assignee changed to: "msofer"
  2. cmimetype changed to: "text/plain"
  3. comment changed to:
    
    Extensions have a number of ways
    to get hold of a Tcl_Command value.
    The routines Tcl_(NR)Create(Obj)Command,
    Tcl_GetCommandFromObj, Tcl_FindCommand,
    Tcl_CreateEnsemble, and Tcl_FindEnsemble
    are sources of them.
    
    Other Tcl routines take Tcl_Command
    token values as arguments.
    
    The potential for trouble is a
    situation where the command is deleted
    between the time Tcl gives the
    Tcl_Command value to the extension
    and the time the extension passes it
    back.  Since a (Tcl_Command) value
    is really a (Command *), in these
    situations the extension may be passing
    back a pointer to memory that's freed,
    or even reallocated to a new purpose,
    setting the stage for crashes or memory
    corruption.
    
    The Command struct has a refCount field
    to keep the struct from being freed while
    various parts of the Tcl internals still
    hold references to it.  This is not exposed
    to extensions, though.  The Tcl_Command value
    has also not been set up to enable Tcl_Preserve().
    
    The callers of Tcl_*Create*Command at least
    have control over the Tcl_CmdDeleteProc so
    they can erect some sort of notification scheme
    about when their save Tcl_Command token values
    are no longer safe to use.
    
    The Tcl_Find*, Tcl_GetCommandFromObj, and
    Tcl_CreateEnsemble routines don't have even
    that.  Perhaps a delete trace can be used to
    achieve the same purpose.
    
    There seems to be a mismatch in the
    responsibilities of an extension (don't pass
    back an invalid Tcl_Command) and the power
    tools at its disposal (routine to test validity,
    or notification when validity is going away,
    or documented examples of how to use what tools
    do exist effectively) to live up to those responsibilities.
    
    I put this in the [namespace] category because
    I've encountered this problem with tokens
    returned by Tcl_CreateEnsemble.  
    
    
  4. foundin changed to: "None"
  5. is_private changed to: "0"
  6. priority changed to: "5 Medium"
  7. resolution changed to: "None"
  8. status changed to: "Open"
  9. submitter changed to: "dgp"
  10. subsystem changed to: "21. [namespace]"
  11. title changed to: "Tcl_Command validity management"
  12. type changed to: "RFE"