Overview
| Artifact ID: | 61b15ff00c4e4c84fa8fbb3499b3c26a3fe048c9 |
|---|---|
| Ticket: | 2939073fffffffffffffffffffffffffffffffff
Unset PATTERN unsafe with trace-originated secondary unsets |
| User & Date: | ferrieux on 2010-02-01 08:33:40 |
Changes
- icomment:
Ha ! Got it now. In truth the secondary unset _does_ kill the hash entry in that case, it's just that the reuse of the freed block doesn't cause immediate harm normally. Hence I had to add the following 'sanitizing' line to FreeVarEntry: if (TclIsVarUndefined(varPtr) && !TclIsVarTraced(varPtr) && (VarHashRefCount(varPtr) == 1)) { +varPtr->value.objPtr=(void *)0xdeadbeef; ckfree((char *) varPtr); It is simply a matter of resetting a field to a visibly invalid value just before freeing. The effect is that, as soon as somebody reuses that freed structure (and typically by indirections off this objPtr field), a SIGSEGV or SIGBUS will burst on 0xdeadbeef. And it does: given this sanitizing patch, the following ultrashort example crashes tclsh: array set x {e 1 i 1} trace add variable x unset rem proc rem args { puts REM:$args if {![info exists ::already]} { set ::already 1 unset ::x(e) } } array unset x * Explanation: a nascent array with a small size has only 4 buckets, allowing a quick search of collisions. It turns out 'e' and 'i' fall in the same bucket. Since the entries of a same bucket are stored in a LIFO linked list, the [array unset x *] iteration will do 'i', then 'e'. The rest of the code arranges for the 'e' to be removed as a side effect of the unset trace on 'i', hence removing the rug. Boom. Renaming the bug according to this confirmation. - login: "ferrieux"
- mimetype: "text/plain"
- username: "ferrieux"