Menu

#5142 segfault in CatchObjCmdCallback

current: 8.6.0
closed-fixed
9
2012-12-13
2012-12-13
No

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 ***

Discussion

  • miguel sofer

    miguel sofer - 2012-12-13
    • milestone: --> current: 8.6.0
     
  • miguel sofer

    miguel sofer - 2012-12-13

    The problem is with $::errorInfo, the script runs without crashing if we put $::nothing instead

     
  • miguel sofer

    miguel sofer - 2012-12-13

    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.

     
  • miguel sofer

    miguel sofer - 2012-12-13
    • status: open --> closed-fixed
     
  • Don Porter

    Don Porter - 2012-12-13
    • status: closed-fixed --> open
     
  • Don Porter

    Don Porter - 2012-12-13

    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

     
  • Don Porter

    Don Porter - 2012-12-13

    And the worse counterpart:

    catch error -> noSuchNs::var

     
  • Jan Nijtmans

    Jan Nijtmans - 2012-12-13

    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

     
  • Jan Nijtmans

    Jan Nijtmans - 2012-12-13

    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

     
  • Don Porter

    Don Porter - 2012-12-13

    The options dictionary variable gets set
    for all return codes.

    Fixed on 8.5 and 8.6 branches

     
  • Don Porter

    Don Porter - 2012-12-13
    • status: open --> closed-fixed