Skip to content
Tcl Source Code Ticket Change Details
Login

Ticket Change Details

Overview

Artifact ID: 36a40fef7b72000443af7ffac1789aad5e806b65
Ticket: 218979ffffffffffffffffffffffffffffffffff
improper use of catch command crashes the interpreter
User & Date: nobody on 2000-10-26 01:08:53
Changes

  1. assignee changed to: "nobody"
  2. cmimetype changed to: "text/plain"
  3. comment changed to:
    OriginalBugID: 3412 Bug
    Version: 8.2
    SubmitDate: '1999-11-05'
    LastModified: '2000-01-20'
    Severity: CRIT
    Status: Released
    Submitter: techsupp
    ChangedBy: hobbs
    OS: Windows NT
    OSVersion: 4.0 / SP4
    FixedDate: '2000-01-20'
    FixedInVersion: 8.3
    ClosedDate: '2000-10-25'
    
    
    Name:
    Borivoj Tydlitat
    
    ReproducibleScript:
    //d> tclsh (or tclshd)
        % proc foo {args} {
          foreach v $args {
            upvar $v var
                puts "variable $v existence: [info exists var]"
          }
        }
        % foo a
        variable a existence: 0
        % catch [info body foo]
    
    ObservedBehavior:
    coredumps (crashes) on NT 4.0, reading NULL page
        correctly returns 1 on AIX 4.2 (NULL page is readable on AIX without
        generating an exception)
    
    
    
    Verified on Linux with 8.3b2. Minimal case seems to be:
    
    --------------------------------------------
    
    proc foo {} {set a 1}
    foo
    catch [info body foo]
    
    --------------------------------------------
    
    In other words, a proc with a local variable is enough to do it.  The proc must be compiled before the catch.  Perhaps the compiler is doing something uncouth with compiledLocals?
    
    - eric
    
    -- 01/17/2000 ericm
    
    The real problem lies in that catch should never use another's
    byte code, which is the case here.  Take the following example:
    
    proc foo a { set b $a }
    foo 1
    proc bar {} { set c 4; set d 3; set a 2; catch [info body foo] ; set d }
    bar
    returns => 4
    
    In foo, the indexed compiled locals a 1:a and 2:b.  What the catch
    above will do is get the value of local 1 in bar and set local 2 to it
    (d gets c in this case). 
    -- 01/17/2000 hobbs
    Well, there were two ways to go about solving this, and we decided
    on what might not be the most "correct" path, but one that should
    work 100%.  It seems that the only possible way to cause the above
    offensive bytecode use is through the use of [info body].  Thus,
    we changed [info body] to always return a string.
    
    The second, "correct" solution requires adding several extra checks
    to Tcl_EvalObjEx, checking that the bytecode we are about to use is
    actually being used in the correct proc context.  I've left that
    code there, #def'd out, so that we have it for reference should it
    come to pass that the above assumption (that [info body] is the only
    thing that can cause this to pass) is false. 
    -- 01/20/2000 hobbs
    
    
    
  4. foundin changed to: "obsolete: 8.2"
  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: "10. Objects"
  10. title changed to:
    improper use of catch command crashes the interpreter
    
  11. type changed to: "Bug"