Skip to content
Tcl Source Code History Of Ticket 7a87a9bc5b
Login

History Of Ticket 7a87a9bc5b

Artifacts Associated With Ticket 7a87a9bc5b

  1. Ticket change [ee4213af8f] (rid 142805) by pointsman on 2015-08-13 13:22:13:

    1. assignee initialized to: "nobody"
    2. closer initialized to: "nobody"
    3. cmimetype initialized to: "text/plain"
    4. comment initialized to:
      With [ca76ce47255c6] (current trunk), valgrind shows an invalid write:
      
      	==14375== Invalid write of size 8
      	==14375==    at 0x4F51D0C: TEBCresume (tclExecute.c:4189)
      	==14375==    by 0x4E7B147: TclNRRunCallbacks (tclBasic.c:4389)
      	==14375==    by 0x4E7AA15: Tcl_EvalObjv (tclBasic.c:4119)
      	==14375==    by 0x4E7CE94: TclEvalEx (tclBasic.c:5258)
      	==14375==    by 0x4E7C233: Tcl_EvalEx (tclBasic.c:4923)
      
      The bug is triggered for me by something, that the tcltest framework does. I see it e.g. with a call
      
      valgrind ./tcltest ../tests/all.tcl -file foo.bar
      
      (Note, that this actually doesn't run any tests. The invalid read also shows, if there are tests executed.)
      
      It seems, the problem was introduced by check-in [41d3e42dda] (2015-07-18). It's about this code block:
      
      4181: 		if (!TclIsVarUndefined(varPtr)) {
      4182: 		    TclDecrRefCount(varPtr->value.objPtr);
      4183: 		    TclSetVarUndefined(varPtr);
      4184: 		    TclClearVarNamespaceVar(varPtr);
      4185: 		    TclCleanupVar(varPtr, arrayPtr);
      4186: 		} else if (flags & TCL_LEAVE_ERR_MSG) {
      4187: 		    goto slowUnsetArray;
      4188: 		}
      4189: 		varPtr->value.objPtr = NULL;
      
      The check-in 41d3e42dda added at this place the 3 lines 4183-4185. Now, the new line 4185
      
       TclCleanupVar(varPtr, arrayPtr);
      
      obviously ckfrees varPtr. This results now - in line 4189 - in an invalid write.
      
      A possible fix seem easy (see below). With that change, the test suite run with the same result as without this change. But I'm just looking at this few lines, without deeper understandig of that code and what happens in detail. So, please check.
      
      --- tclExecute.c
      +++ tclExecute.c
      @@ -4183,12 +4183,13 @@
       		    TclSetVarUndefined(varPtr);
       		    TclClearVarNamespaceVar(varPtr);
       		    TclCleanupVar(varPtr, arrayPtr);
       		} else if (flags & TCL_LEAVE_ERR_MSG) {
       		    goto slowUnsetArray;
      -		}
      -		varPtr->value.objPtr = NULL;
      +		} else {
      +                    varPtr->value.objPtr = NULL;
      +                }
       		TRACE_APPEND(("OK\n"));
       		NEXT_INST_F(6, 1, 0);
       	    } else if (!varPtr && !(flags & TCL_LEAVE_ERR_MSG)) {
       		/*
       		 * Don't need to do anything here.
      
    5. foundin initialized to: "trunk"
    6. is_private initialized to: "0"
    7. login: "pointsman"
    8. priority initialized to: "5 Medium"
    9. resolution initialized to: "None"
    10. severity initialized to: "Minor"
    11. status initialized to: "Open"
    12. submitter initialized to: "pointsman"
    13. subsystem initialized to: "- New Builtin Commands"
    14. title initialized to: "Invalid write in tclExecute.c"
    15. type initialized to: "Bug"
  2. Ticket change [06e770b0fa] (rid 142810) by dgp on 2015-08-13 16:54:47:

    1. assignee changed to: "dkf"
    2. login: "dgp"
    3. mimetype: "text/plain"
    4. priority changed to: "8"
  3. Ticket change [122391f8d3] (rid 142816) by dkf on 2015-08-17 12:36:55:

    1. login: "dkf"
    2. mimetype: "text/plain"
    3. subsystem changed to: "47. Bytecode Compiler"
  4. Ticket change [2c3b0c9c21] (rid 142822) by dkf on 2015-08-17 17:08:44:

    1. icomment:
      I suspect that simply deleting the line
      <pre>
      		varPtr->value.objPtr = NULL;
      </pre>
      would be sufficient to fix this bug. This is because I know that being undefined is the same as having that field be NULL; either the value is not NULL, in which case the first <tt>if</tt> clause above activates (and makes the field NULL) or it is NULL in which case the write ought to have no effect.
      <p>
      I'd appreciate if you could check if my theory is correct. I don't have valgrind on this system (OSX).
      
    2. login: "dkf"
    3. mimetype: "text/html"
    4. username: "dkf"
  5. Ticket change [5d8221351e] (rid 142827) by dkf on 2015-08-17 18:05:05:

    1. icomment: "My proposed fix is [4a4e3eb33d]."
    2. login: "dkf"
    3. mimetype: "text/x-fossil-wiki"
    4. username: "dkf"
  6. Ticket change [4b4814e5c9] (rid 142842) by pointsman on 2015-08-17 20:57:10:

    1. icomment:
      Switched to that branch, rebuild with the necessary valgrind magic and run the whole test suite (with -singleproc 1) - only without clock.test - under valgrind. No invalid memory read or write reported with this.
      
    2. login: "pointsman"
    3. mimetype: "text/plain"
  7. Ticket change [bb893f8edf] (rid 142844) by dkf on 2015-08-18 07:03:58:

    1. closedate changed to: "2457252.7944263"
    2. closer changed to: "dkf"
    3. icomment: "Thanks for the check. Fixed."
    4. login: "dkf"
    5. mimetype: "text/html"
    6. resolution changed to: "Fixed"
    7. status changed to: "Closed"
    8. username: "dkf"