Overview
| Artifact ID: | ad38752eb89bb9ca3cbd9234215ec2eb1ecedbba |
|---|---|
| Ticket: | d59715d0cffb0b86427b164188c95f2a06d88c17
Use-after-free in Tcl_DStringAppend |
| User & Date: | dah on 2016-06-21 00:53:43 |
Changes
- icomment:
Danger, Will Robinson There's some wicked action going on in Tk. In generic/tkwindow.c in function Initialize approx line 3193 We hit this code path: /* * Figure out the application's name and class. */ Tcl_DStringInit(&class); if (name == NULL) { int offset; TkpGetAppName(interp, &class); offset = Tcl_DStringLength(&class)+1; Tcl_DStringSetLength(&class, offset); Tcl_DStringAppend(&class, Tcl_DStringValue(&class), offset-1); name = Tcl_DStringValue(&class) + offset; } What's the problem here? If we're working with a string longer than will fit in DString's static storage then DStringAppend can ckrealloc here, but we're passing a pointer to the very memory we're reallocating! This code doesn't make sense to me either, why is it taking a name 'foo' and appending it onto itself? I think it can be reduced to simply this: if (name == NULL) { TkpGetAppName(interp, &class); name = Tcl_DStringValue(&class); } I can provide a demo if necessary but I believe this evil line: Tcl_DStringAppend(&class, Tcl_DStringValue(&class), offset-1); speaks for itself and indeed is the culprit here. Finally and a bit unrelated, there are limits to Window class names, On Microsoft Windows the max is 256 (OS limitation). So if you get crazy with long names, Tk will silently not display any window. - login: "dah"
- mimetype: "text/plain"
- username: "dah"