Skip to content
Tcl Source Code View Ticket
Login

View Ticket

2000-10-26
08:33 • Closed ticket [218979ffff]: improper use of catch command crashes the interprete... artifact: 7963efb78f user: welch
01:08 • New ticket [218979ffff]. artifact: 36a40fef7b user: nobody

improper use of catch command crashes the interpreter

Closed / Fixed218979ffffffffffffffffffffffffffffffffffCreated 26 years agoUpdated 26 years ago
Descriptionplain2000-10-26 01:08:53
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
welch Closed ticket [218979ffff]. [History diff]2000-10-26 08:33:07
Log in (anonymous is fine) to add a comment.