Skip to content
Tcl Source Code View Ticket
Login

View Ticket

2012-12-13
23:29 • Closed ticket [3595576fff]: segfault in CatchObjCmdCallback plus 7 other cha... artifact: 01d85c347e user: dgp
23:19 • Ticket [3595576fff]: 4 changes artifact: 950e58bacc user: nijtmans
23:15 • Ticket [3595576fff]: 4 changes artifact: 8afe0edd83 user: nijtmans
22:50 • Ticket [3595576fff]: 4 changes artifact: 700879498f user: dgp
22:49 • Open ticket [3595576fff]. artifact: cf9281cd3e user: dgp
20:37 • Closed ticket [3595576fff]. artifact: b714f64652 user: msofer
20:23 • Ticket [3595576fff]: 4 changes artifact: 40afb09324 user: msofer
20:18 • Ticket [3595576fff]: 1 change artifact: 19dea94080 user: msofer
13:17 • New ticket [3595576fff]. artifact: e52e4ef1cd user: msofer

segfault in CatchObjCmdCallback

Closed / Fixed3595576fffffffffffffffffffffffffffffffffCreated 14 years agoUpdated 14 years ago
Descriptionplain2012-12-13 13:17:43
Mem corruption, detected by andrewsh

mig@T510:~/DEVEL/tcl-core/trunk/unix$ cat /tmp/test.tcl 
for {set i 0} {$i < 5} {incr i} {
    catch {catch {source foo} puts $::errorInfo}
}
puts DONE
mig@T510:~/DEVEL/tcl-core/trunk/unix$ ./tclsh /tmp/test.tcl 
*** glibc detected *** ./tclsh: invalid fastbin entry (free): 0x0000000001e67430 ***
msofer Ticket [3595576fff]: 1 change [History diff]2012-12-13 20:18:38
msoferplain2012-12-13 20:23:56
The problem is with $::errorInfo, the script runs without crashing if we put $::nothing instead
msoferplain2012-12-13 20:37:42
allow_comments - 1

Valgrind sees the crash at line 364 in tclCmdAH.c: there is a decrRefCount of the 'options' Tcl_Obj which was already freed from Tcl_ObjSetVar2 in the line above.

Tcl_ObjSetVar2 is "fire and forget" with respect to the newValuePtr - it will clear a Tcl_Obj with 0 reference count. This means that line 364 is wrong, it should not be there at all.

Fixed in trunk.
dgpplain2012-12-13 22:49:18
allow_comments - 0


The ::errorInfo in the demo really clouds the issue.

Here's the simplified bug demo that gets to the heart of
the matter:

catch {} -> noSuchNs::var
dgpplain2012-12-13 22:50:47
And the worse counterpart:

catch error -> noSuchNs::var
nijtmansplain2012-12-13 23:15:46
In line 359:
    if (objc == 4 ) {
Shouldn't that be:
    if (result == TCL_ERROR && objc == 4 ) {

The Tcl_GetReturnOptions() function should
only be called if the script returned an error, isn't it?

This appears to fix the crash.

Regards,
        Jan Nijtmans
nijtmansplain2012-12-13 23:19:35
B.T.W.: Tcl 8.5 has the same bug, only the
given lines are in Tcl_CatchObjCmd (tclCmdAH.c lines 273/276)

So it's not an NRE bug, It's a TIP #280 implementation bug ;-)

Regards,
        Jan Nijtmans
dgpplain2012-12-13 23:29:38
allow_comments - 1

The options dictionary variable gets set
for all return codes.

Fixed on 8.5 and 8.6 branches
Log in (anonymous is fine) to add a comment.