Skip to content
Tcl Source Code View Ticket
Login

View Ticket

Bytecode for [catch] causes crash

Closed / Fixed3098302fffffffffffffffffffffffffffffffffCreated 16 years agoUpdated 16 years ago
Descriptionplain2010-10-29 15:29:43
If a [catch {some script} result] or [catch {some script} result options] has a write trace fail on the 'result' or 'options' variables, the 'endCatch' bytecode for the catch block gets bypassed, and the exception stack becomes unbalanced. The result is somewhat unpredictable, but likely to be unamusing:

Test case:

proc failtrace {n1 n2 op} {
    return -code error "trace on $n1 fails by request"
}
trace add variable result1 write failtrace

proc x {} {
    variable result1
    for {set i 0} {$i < 100} {incr i} {
set status2 [catch {
    set status1 [catch {
return -code error -level 0 "original failure"
    } result1 options1]
} result2 options2]
lappend retval $status2 $result2 $options2
    }
}

puts [x]

Test result:

Bad stack top 7 at pc 144 in TclNRExecuteByteCode (min 0, max 6)
 executing lappend retval $status2 $result2 $options2
TclNRExecuteByteCode execution failure: bad stack top

Will follow up on tcl-core.
kennykbplain2010-10-30 00:51:16
File Added - 391664: Bytecode safety and exception ranges..txt
kennykbplain2010-10-30 00:51:53
File Added - 391665: bytecodeDump.txt
kennykbplain2010-10-31 00:10:49
File Added - 391729: catch.patch
kennykbplain2010-10-31 01:14:18
File Deleted - 391729:
kennykbplain2010-10-31 01:14:56
File Added - 391732: catch.patch
dkfplain2010-11-03 03:09:58
I *think* the patch is correct.
kennykbplain2010-11-03 08:13:03
dkf's blessing is good enough for me. committed the patch and backported onto core-8-5-branch. Leaving this one 'Pending' in case dgp has another opinion.
sf-robotplain2010-11-17 08:20:02
This Tracker item was closed automatically by the system. It was
previously set to a Pending status, and the original submitter
did not respond within 14 days (the time period specified by
the administrator of this Tracker).
sf-robot Closed ticket [3098302fff]. [History diff]2010-11-17 08:20:03
Log in (anonymous is fine) to add a comment.

Attachments: