Skip to content
Tcl Source Code History Of Ticket 2152286fffffffff
Login

History Of Ticket 2152286fffffffff

Artifacts Associated With Ticket 2152286fffffffff

  1. Ticket change [1384f2aa79] (rid 124236) by fadib on 2008-10-07 22:39:05:

    1. assignee initialized to: "msofer"
    2. cmimetype initialized to: "text/plain"
    3. comment initialized to:
      Please see the attached testcase (tcltest.tar.gz)
      
      Problem Analysis:
      ----------------
      The problem happens when a C function calls a TCL proc that calls a C function that returns TCL_RETURN, this causes returnLevel to be decremented all the way to 0 causing TclUpdateReturnInfo() to panic.
      
      Testcase:
      --------
       + (tcltest.c): main() calls CProcCmd() function which is a C function with a TCL wrapper.
       + CProcCmd() calls tclproc (tcltest.tcl) which calls CProcCmd() again.
       + CProcCmd() returns TCL_RETURN which makes TCL panic.
      
      Workarounds:
      -----------
      There are two workarounds that I can use to make the testcase work (uncomment either line 25 or 28 in tcltest.c):
      
      + Workaround 1 (line 25): 
      Explicitly increment returnLevel before returning TCL_RETURN.
      
      + Workaround 2 (line 28): 
      Call a dummy tcl proc before returning TCL_RETURN. This works because it forces the returllevel to be incremented once and thus stops it from ever reaching 0.
      
      
      
    4. foundin initialized to: "obsolete: 8.5.4"
    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: "fadib"
    10. subsystem initialized to: "45. Parsing and Eval"
    11. title initialized to: "TCL_RETURN causes TclUpdateReturnInfo() to panic"
    12. type initialized to: "Bug"
  2. Ticket change [2d00ca89e9] (rid 119010) by fadib on 2008-10-08 05:39:05:

    1. icomment:
      
      
      File Added - 296501: tcltest.tar.gz
      
      
      
    2. login: "fadib"
    3. mimetype: "text/plain"
    4. username: "fadib"
  3. Ticket change [18f3a2e063] (rid 122743) by fadib on 2008-10-08 05:39:47:

    1. priority changed to: "7 High"
  4. Ticket change [19ee4d495b] (rid 122885) by fadib on 2008-10-08 05:43:21:

    1. icomment:
      
      
      File Deleted - 296501: 
      
      
      
      File Added - 296502: tcltest.tar.gz
      
      File Added: tcltest.tar.gz
      
      
    2. login: "fadib"
    3. mimetype: "text/plain"
    4. username: "fadib"
  5. Add attachment "tcltest.zip" [cecae8a57c] (rid 96111) by fadib on 2008-10-08 05:47:23.

  6. Ticket change [478d68e075] (rid 99722) by fadib on 2008-10-08 05:47:23:

    1. icomment:
      
      
      File Added - 296503: tcltest.zip
      
      File Added: tcltest.zip
      
      
    2. login: "fadib"
    3. mimetype: "text/plain"
    4. username: "fadib"
  7. Ticket change [4c405fdb3d] (rid 126853) by msofer on 2008-10-08 05:48:37:

    1. icomment:
      That file seems to be corrupt:
      
      mig@oli:/tmp$ tar -ztf /tmp/tcltest.tar.gz 
      tar: This does not look like a tar archive
      tar: Skipping to next header
      tar: Error exit delayed from previous errors
      
      
      
    2. login: "msofer"
    3. mimetype: "text/plain"
    4. username: "msofer"
  8. Ticket change [7055242c59] (rid 100459) by fadib on 2008-10-08 05:50:00:

    1. icomment:
      
      
      File Deleted - 296502: 
      
      Please use the .zip file
      
      
    2. login: "fadib"
    3. mimetype: "text/plain"
    4. username: "fadib"
  9. Ticket change [a5b77ea599] (rid 110423) by msofer on 2008-10-08 05:56:05:

    1. assignee changed to: "dgp"
  10. Ticket change [359a6ac138] (rid 106967) by dgp on 2008-10-17 04:48:03:

    1. icomment:
      
      The flaw here is in the CProcCmd()
      routine.  Several places in that routine
      Tcl_Eval is called on some script, but
      the return code is not checked.  If you
      were to check it, you would find the
      value to be TCL_RETURN, which is typically
      an indication that you should not just
      continue normally.  Your code continues
      normally.
      
      
    2. login: "dgp"
    3. mimetype: "text/plain"
    4. username: "dgp"
  11. Ticket change [877fa264ef] (rid 131705) by dgp on 2008-10-17 04:51:25:

    1. icomment:
      
      A quick attempt to patch up that
      flaw does not resolve the issue, 
      so I'll examine further.  In the meantime,
      do not confuse the coding of 
      procs, which push CallFrames, and
      non-proc commands, which do not.
      
      
    2. login: "dgp"
    3. mimetype: "text/plain"
    4. username: "dgp"
  12. Ticket change [a29f465408] (rid 109927) by dgp on 2008-10-20 01:52:36:

    1. icomment:
      
      The error here is in the evaluation
      of [cproc 1].  With a single argument
      the branch is taken that evaluates
      [tclproc].  If you examine the return
      code from that Tcl_Eval(), you will
      find that it is TCL_OK.  The command
      [tclproc] has run successfully.
      
      You then turn around and originate a
      TCL_RETURN return code, without
      dealing with the fact that an
      intervening Tcl_Eval() has taken
      the interp out of the reset state
      it had when it entered CProcCmd.
      
      There are a number of ways to
      fix the code, depending on just
      what it is this code is intended
      to do.  That is not clear at all
      from the example, which feels 
      contrived to demo the conditions
      for panic, more than directed
      toward any rational purpose.  That's
      fine; that's often true of bug
      demos, but leaves me without any
      context to choose what alternative
      might make sense.
      
      If you have a Tcl_ObjCmdProc that
      will return TCL_RETURN, you should
      either do that with the interp
      still in its original reset state,
      or do that after something you called
      also returned TCL_RETURN (the "pass
      along the exception" case), or take
      care to call Tcl_SetReturnOptions()
      to set the relevant options as needed
      for your command (the "I'm originating
      TCL_RETURN for my own purposes" case).
      
      It seems to me the panic is serving
      exactly the purpose intended, to call
      attention to C code that's not robust
      or safe so it can get corrected.
      
      Note that your workarounds are just
      tricky indirect ways to take my advice.
      Explicit returnLevel increment is just
      a sneaky "probe the internals" way to
      accomplish what a proper Tcl_SetReturnOptions()
      call would do.  The dummy proc call is just
      a very indirect way to call the
      Tcl_ResetResult() you need to get the
      interp back to an initial state where
      simple return of TCL_RETURN will cause
      no trouble.
      
      Hope that helps.  I'll keep this report
      pending in case you want to comment
      further or seek advice.
      
      
      
    2. login: "dgp"
    3. mimetype: "text/plain"
    4. username: "dgp"
  13. Ticket change [1da2abf3cf] (rid 90843) by dgp on 2008-10-20 01:52:37:

    1. closedate changed to: "2008-10-19T18:52:37"
    2. closer changed to: "dgp"
    3. resolution changed to: "Invalid"
    4. status changed to: "Pending"
  14. Ticket change [f37e65dde9] (rid 129730) by dgp on 2008-10-20 02:27:31:

    1. icomment:
      
      Ok, none of my last comment
      is wrong, exactly, but it
      did miss the point.  Whether
      or not C code calling Tcl
      should do what the demo does, it's
      now apparent that a small,
      simple, safe change to Tcl
      itself will permit it to
      tolerate such code, and that's
      good for all.
      
      Testing that change now...
      
      
      
    2. login: "dgp"
    3. mimetype: "text/plain"
    4. resolution changed to: "Remind"
    5. status changed to: "Open"
    6. username: "dgp"
  15. Ticket change [47d14ef894] (rid 99769) by dgp on 2008-10-20 02:31:47:

    1. icomment:
      
      diff -u -r1.139.2.3 tclProc.c
      --- generic/tclProc.c   11 Aug 2008 19:01:59 -0000      1.139.2.3
      +++ generic/tclProc.c   19 Oct 2008 19:30:06 -0000
      @@ -2245,6 +2245,10 @@
              if (code == TCL_ERROR) {
                  iPtr->flags |= ERR_LEGACY_COPY;
              }
      +       if (code != TCL_RETURN) {
      +           iPtr->returnLevel = 1;
      +           iPtr->returnCode = TCL_OK;
      +       }
           }
           return code;
       }
      
      
      
    2. login: "dgp"
    3. mimetype: "text/plain"
    4. username: "dgp"
  16. Add attachment "2152286.patch" [81da296fd1] (rid 117121) by dgp on 2008-10-20 02:50:54.

  17. Ticket change [1636e763c2] (rid 124682) by dgp on 2008-10-20 02:50:54:

    1. icomment:
      
      
      File Added - 297976: 2152286.patch
      
      
      
    2. login: "dgp"
    3. mimetype: "text/plain"
    4. username: "dgp"
  18. Ticket change [95fe8354a2] (rid 106241) by dgp on 2008-10-20 02:50:55:

    1. icomment:
      
      even simpler patch attached.
      File Added: 2152286.patch
      
      
    2. login: "dgp"
    3. mimetype: "text/plain"
    4. username: "dgp"
  19. Ticket change [117b16ecca] (rid 95150) by dgp on 2008-10-20 02:55:59:

    1. closedate changed to: "2008-10-19T19:55:59"
    2. closer changed to: "dgp"
    3. icomment:
      committed for 8.5.6 and 8.6b1
      
      
    4. login: "dgp"
    5. mimetype: "text/plain"
    6. resolution changed to: "Fixed"
    7. status changed to: "Closed"
    8. username: "dgp"