Skip to content
Tcl Source Code View Ticket
Login

View Ticket

2010-10-07
10:06 • Closed ticket [3081065fff]: post-free writes to Tcl_Obj fields plus 6 other ... artifact: 22607b3257 user: dgp
10:06 • Ticket [3081065fff]: 4 changes artifact: 22605914c0 user: dgp
04:06 • Add attachment tclCompile.patch to ticket [3081065fff] artifact: a9bed8765e user: nijtmans
04:06 • Ticket [3081065fff] post-free writes to Tcl_Obj fields status still Open wit... artifact: f023c6f29a user: nijtmans
04:05 • Open ticket [3081065fff]. artifact: 7efd6d14c0 user: nijtmans
04:05 • Ticket [3081065fff]: 4 changes artifact: b0167622c0 user: nijtmans
01:39 • Closed ticket [3081065fff]. artifact: d30ea9e5ff user: dgp
01:24 • Ticket [3081065fff]: 4 changes artifact: 8e0008325f user: dgp
01:23 • Ticket [3081065fff]: 4 changes artifact: f0227c3a50 user: dgp
01:23 • Add attachment 3081065.patch to ticket [3081065fff] artifact: 83d9911f0b user: dgp
2010-10-05
23:30 • Ticket [3081065fff] post-free writes to Tcl_Obj fields status still Open wit... artifact: 1a87cc709c user: dgp
23:03 • Ticket [3081065fff]: 2 changes artifact: 65f06fbbc5 user: dgp
23:03 • Ticket [3081065fff]: 1 change artifact: c3efec60d2 user: dgp
20:20 • Ticket [3081065fff]: 4 changes artifact: 5790fa7c06 user: dgp
20:20 • Add attachment demo.tcl to ticket [3081065fff] artifact: 595cf44445 user: dgp
20:19 • Ticket [3081065fff] segfault in httpold.test status still Open with 2 other ... artifact: 2571958c89 user: dgp
20:19 • Ticket [3081065fff]: 4 changes artifact: 8e8b9d14da user: dgp
03:41 • Ticket [3081065fff]: 4 changes artifact: 5abdd5dba6 user: kennykb
02:35 • Ticket [3081065fff]: 4 changes artifact: 24b3109125 user: msofer
01:33 • Ticket [3081065fff]: 4 changes artifact: bb009580b7 user: dgp
2010-10-04
18:25 • New ticket [3081065fff]. artifact: 32da69bd6c user: dgp

post-free writes to Tcl_Obj fields

Closed / Fixed3081065fffffffffffffffffffffffffffffffffCreated 16 years agoUpdated 16 years ago
Descriptionplain2010-10-04 18:25:22
Tcl HEAD:

$ make test TESTFLAGS='-singleproc 1 -file "http.test httpold.test"'
...
http.test
Running httpd in thread 1080544144
httpold.test
Running http 1.0 tests in slave interp
httpold.test:   Total   31      Passed  31      Skipped 0       Failed  0
make: *** [test-tcl] Segmentation fault

segfault after [tcltest::cleanupTests] returns.
dgpplain2010-10-05 01:33:27
Narrowing it down, same segfault from:

make test TESTFLAGS='-singleproc 1 -file "http.test httpold.test" -match httpold-5.1'

so only one test is run.
msoferplain2010-10-05 02:35:09
no repro here, and valgrind looks happy enough
kennykbplain2010-10-05 03:41:24
Stack trace:

==24462== Invalid read of size 4
==24462==    at 0x4137C32: MoveObjs (tclThreadAlloc.c:719)
==24462==    by 0x413794F: TclThreadFreeObj (tclThreadAlloc.c:630)
==24462==    by 0x4115C3E: TclFreeObj (tclObj.c:1447)
==24462==    by 0x414AA06: DeleteArray (tclVar.c:5430)
==24462==    by 0x414649E: UnsetVarStruct (tclVar.c:2532)
==24462==    by 0x414A69F: TclDeleteNamespaceVars (tclVar.c:5253)
==24462==    by 0x410F89E: TclTeardownNamespace (tclNamesp.c:1053)
==24462==    by 0x4052B0B: DeleteInterpProc (tclBasic.c:1419)
==24462==    by 0x4125AF8: Tcl_EventuallyFree (tclPreserve.c:299)
==24462==    by 0x4052944: Tcl_DeleteInterp (tclBasic.c:1308)
==24462==    by 0x40E8DEE: SlaveObjCmdDeleteProc (tclInterp.c:2587)
==24462==    by 0x4054A41: Tcl_DeleteCommandFromToken (tclBasic.c:3021)
==24462==  Address 0x10 is not stack'd, malloc'd or (recently) free'd
dgpplain2010-10-05 20:19:47
Attached is a demo script.

The crash is in MoveObjs in the
thread-enabled allocator.  The chain
of Tcl_Obj's is corrupted with a NULL
value where a link in the chain ought
to be.

Suspect the real cause must be something
continuing to write NULLs to an intrep after
the Tcl_Obj has been freed.  The <substcode>
Tcl_ObjType is a likely suspect, but not yet
confirmed.
dgp Ticket [3081065fff]: 2 changes [History diff]2010-10-05 20:19:48
dgpplain2010-10-05 20:20:30
File Added - 388895: demo.tcl
dgp Ticket [3081065fff]: 1 change [History diff]2010-10-05 23:03:29
dgp Ticket [3081065fff]: 2 changes [History diff]2010-10-05 23:03:58
dgpplain2010-10-05 23:30:13
When calling TclCleanupByteCode()
to free the internal rep of a Tcl_Obj, it is
possible to reduce the refcount on that same
Tcl_Obj to zero, causing it to be freed.  This
means a freeIntRepProc ought not be writing
to the objPtr->fields after TCBC returns.
dgpplain2010-10-07 01:23:01
File Added - 389085: 3081065.patch
dgpplain2010-10-07 01:24:19
Attached is a fix with test.
dgpplain2010-10-07 01:39:12
allow_comments - 1

Committed.
nijtmansplain2010-10-07 04:05:00
Two minor observations:
- If this can happen in FreeSubstCodeInternalRep, then
it can happen in FreeByteCodeInternalRep as well.
- After modifying FreeByteCodeInternalRep, it's
implementation is equal to FreeSubstCodeInternalRep,
so one of them could be eliminated.

I don't know if a test case can be found for this,
but better safe than sorry. Here is a patch. The
FreeByteCodeInternalRep change should be
backported to 8.5 and 8.4 as well IMHO.
nijtmansplain2010-10-07 04:05:01
allow_comments - 0
nijtmansplain2010-10-07 04:06:53
File Added - 389100: tclCompile.patch
dgpplain2010-10-07 10:06:29
Good observation.  Miguel and I 
are already pursuing that as a separate
issue.  See 467523 and

http://paste.tclers.tk/2216

FreeExprCodeInternalRep is the other
which matches the pattern, and I'll be
changing it as well, though current other
choices in expr compilation are such that
an analogous bug "can't happen".
dgpplain2010-10-07 10:06:31
allow_comments - 1
Log in (anonymous is fine) to add a comment.

Attachments: