Skip to content
Tcl Source Code History Of Ticket 3564735fffffffffffffffffffffffffffffffff
Login

History Of Ticket 3564735fffffffffffffffffffffffffffffffff

Artifacts Associated With Ticket 3564735fffffffffffffffffffffffffffffffff

  1. Ticket change [18868b2f61] (rid 122674) by bgriffin on 2012-09-04 15:38:00:

    1. assignee initialized to: "msofer"
    2. cmimetype initialized to: "text/plain"
    3. comment initialized to:
      I've recently tracked down a crash that was due to faulty coding in an incrTcl methods, however, I don't know if this is a known "problem" with incrTcl, or a bug in the 8.5.8+34 combination, or just the way things are.  I'm also wondering if there shouldn't be a runtime check for this condition.
      
      So what is the problem?
      
      itcl::class Dog {
      variable bite
      method bark {}
      }
      
      itcl::body Dog::bark {} {
      variable bite
      set bite false
      puts "Bark!"
      }
      
      The crash is due to the unnecessary "variable" statement in the itcl::body.  It ends up corrupting the heap. (Thanks for TCL_MEM_DEBUG!)  
      
      $ tclsh8.5
      % package require Itcl
      3.4
      % memory validate on
      % itcl::class Dog {
              variable bite
              method bark {}
      }
      % itcl::body Dog::bark {} {
              variable bite
              set bite false
              puts "Bark!"
      }
      % Dog fido
      fido
      % fido bark
      hi guard byte 0 is 0x62         b
      total mallocs                 114496
      total frees                   103026
      current packets allocated      11470
      current bytes allocated       482362
      maximum packets allocated      15640
      maximum bytes allocated       630832
      high guard failed at 81ba7f8, .../tcl/unix/../generic/tclHash.c 344
      8 bytes allocated at (.../incrTcl/itcl/generic/itcl_migrate.c 130)
      Memory validation failure
      Abort(coredump)
      
      
    4. foundin initialized to: "obsolete: 8.5.12"
    5. is_private initialized to: "0"
    6. priority initialized to: "5 Medium"
    7. resolution initialized to: "None"
    8. status initialized to: "Open"
    9. submitter initialized to: "bgriffin"
    10. subsystem initialized to: "21. [namespace]"
    11. title initialized to: "Tcl8.5 + incrTcl3.4 [variable] crash"
    12. type initialized to: "Bug"
  2. Ticket change [947e8161fc] (rid 105992) by sebres on 2012-09-04 23:13:45:

    1. icomment:
      I could not reproduce it with 8.5.11 and itcl-3-branch on windows. How often is it reproducible?
      
      
      
    2. login: "sebres"
    3. mimetype: "text/plain"
    4. username: "sebres"
  3. Ticket change [b2f1d2788e] (rid 98428) by dgp on 2012-09-05 00:07:09:

    1. icomment:
      
      The failure has been present since the Tcl checkin
      http://core.tcl.tk/tcl/ci/c49c117219 
      which is "modifs to help itcl adapt to VarReform"
      
      For many Tcl checkins prior to that, current Itcl
      source either cannot build or cannot [load].
      
      Appears that this bug is an indication that some
      details of adjusting to Tcl "VarReform" just never
      got done right.
      
      
    2. login: "dgp"
    3. mimetype: "text/plain"
    4. username: "dgp"
  4. Ticket change [dbbde8f55b] (rid 108011) by dgp on 2012-09-05 00:11:57:

    1. icomment:
      Rolling back Itcl to the same era,
      http://core.tcl.tk/itcl/info/3f5de3c16d
      the same problem is present.  This is
      not a recent Itcl regression.
      
      
      
    2. login: "dgp"
    3. mimetype: "text/plain"
    4. username: "dgp"
  5. Ticket change [eed6ce32a9] (rid 108888) by dgp on 2012-09-05 00:21:25:

    1. icomment:
      
      On the bright side, whatever the problem is
      has apparently been resolved in Itcl 4.0b8.
      No troubles there.
      
      
    2. login: "dgp"
    3. mimetype: "text/plain"
    4. username: "dgp"
  6. Ticket change [7180286866] (rid 100687) by msofer on 2012-09-05 02:50:58:

    1. icomment:
      Don: could you please check one rev back for itcl, ie [8d02855363]? That one should compile ok against 8.5 headers. I'm trying to check if it isn't something that I introduced when doing the unholy adaptation for compiling on 8.4 headers and running properly on 8.4 and 8.5
      
      
    2. login: "msofer"
    3. mimetype: "text/plain"
    4. username: "msofer"
  7. Ticket change [110474b306] (rid 95071) by dgp on 2012-09-06 02:39:19:

    1. icomment:
      The memory corruption happens in the execution of
      the INST_VARIABLE instruction in tclExecute.c
      
      The "call" TclSetVarNamespaceVar(otherPtr) corrupts
      the memory.  This is really a macro, and the expansion
      includes the line:
      
      ((VarInHash *)(otherPtr))->refCount++;
      
      This is actually writing one byte past allocated memory,
      so this tells me otherPtr points to a struct that is actually
      smaller in size than a VarInHash struct.  I think this must
      be some Itcl declared struct that the Itcl custom resolvers
      allocate.
      
      I hope that's enough information for msofer to understand
      the problem at a more conceptual level and recommend a fix.
      
      
      
    2. login: "dgp"
    3. mimetype: "text/plain"
    4. priority changed to: "9 Immediate"
    5. username: "dgp"
  8. Ticket change [f0be58c9c1] (rid 109247) by dgp on 2012-09-06 02:45:53:

    1. icomment:
      Looks like the root of the problem is casting a pointer to
      a Var struct to the type of VarInHash struct, and then using
      it to get at extension fields that are not there.  As a guess,
      we're simply not supposed to reach this code in this scenario?
      Some guard somewhere is failing in its duty?
      
      
    2. login: "dgp"
    3. mimetype: "text/plain"
    4. username: "dgp"
  9. Ticket change [1140ae606d] (rid 95109) by dkf on 2012-09-06 06:19:51:

    1. icomment:
      IIRC, the 8.5 series assumes in a few key spots that all variables are either a VarInHash or a member of the LVT. In particular, it assumes that TclObjLookupVarEx(…,TCL_NAMESPACE_ONLY,…) always returns a VarInHash (or NULL, of course). It sounds like Itcl is generating them in another way. I guess we ought to check if the VAR_IN_HASHTABLE flag is set on the otherPtr (i.e., use TclIsVarInHash(otherPtr) as the guard).
      
      One question though: should that be combined into the guard within TclSetVarNamespaceVar? Or should it be exposed in the INST_VARIABLE code? If the latter, I think TclVariableObjCmd has the identical problem. (It should be testable by invoking [variable bite] like [set v variable;$v bite], so as to defeat compilation.)
      
      
    2. login: "dkf"
    3. mimetype: "text/plain"
    4. username: "dkf"
  10. Ticket change [2efe6a6c44] (rid 92976) by dkf on 2012-09-06 06:22:06:

    1. icomment:
      There's also the possibility that Itcl 3 might have the wrong flags set (i.e., setting the VAR_IN_HASHTABLE flag when it was never allocated as a VarInHash). If that's the case, it's got to be slated as an Itcl bug for the sake of our sanity.
      
      
    2. login: "dkf"
    3. mimetype: "text/plain"
    4. username: "dkf"
  11. Ticket change [0d1ccab2c7] (rid 114303) by dgp on 2012-09-06 20:53:55:

    1. icomment:
      Tcl_VariableObjCmd() suffers the same problem.
      
      The (Var *) returned by TclObjLookupVarEx has
      a flags field of 0.
      
      
    2. login: "dgp"
    3. mimetype: "text/plain"
    4. username: "dgp"
  12. Ticket change [03509558db] (rid 119808) by dgp on 2012-09-06 23:08:20:

    1. icomment:
      
      Here's a demonstration of a related flaw:
      
      package require Itcl
      itcl::class Dog {
      method bark {}
      }
      itcl::body Dog::bark {} {
      variable bite
      }
      Dog fido
      fido bark
      
      can't upvar from variable to itself
          while executing
      "variable bite"
          (object "::fido" method "::Dog::bark" body line 2)
          invoked from within
      "fido bark"
      
      These two together indicate some ways in which
      the Itcl custom resolvers aren't quite meeting core
      expectations.
      
      
    2. login: "dgp"
    3. mimetype: "text/plain"
    4. username: "dgp"
  13. Ticket change [71fb9eb0c3] (rid 100786) by dgp on 2012-09-07 02:03:06:

    1. icomment:
      Branch bug-3564735 now contains a patch
      that armors Tcl against memory corruption in
      this scenario.
      
      
    2. login: "dgp"
    3. mimetype: "text/plain"
    4. username: "dgp"
  14. Ticket change [0ae7dd885a] (rid 113901) by dgp on 2012-09-07 19:49:48:

    1. priority changed to: "8"
  15. Ticket change [c5d64a1c74] (rid 121652) by dgp on 2012-09-11 21:08:39:

    1. closedate changed to: "2012-09-11T14:08:39"
    2. closer changed to: "dgp"
    3. icomment:
      
      
      allow_comments - 1
      
      Protection patch committed to relevant
      branches.  Remaining problems are Itcl's
      and reported in the Itcl tracker.
      
      
    4. login: "dgp"
    5. mimetype: "text/plain"
    6. resolution changed to: "Fixed"
    7. status changed to: "Closed"
    8. username: "dgp"