Artifacts Associated With Ticket c383ebb5e414458c
Ticket change [c5ab08f723] (rid 146928) by oehhar on 2016-06-13 12:16:57:
- assignee initialized to: "nobody"
- closer initialized to: "nobody"
- cmimetype initialized to: "text/x-fossil-wiki"
- comment initialized to:
In 8.6.5, when typing: <verbatim> glob -path a </verbatim> my wish core dumps. In 8.5.18, I get: <verbatim> % glob -path a wrong # args: should be "glob ?switches? name ?name ...?" </verbatim> System: * Win 10 64 bit * Wish 8.6.5 compiled by MSVC6, PSDK2003SP1, makefile.vc
- foundin initialized to: "8.6.5"
- is_private initialized to: "0"
- login: "oehhar"
- priority initialized to: "5 Medium"
- private_contact initialized to: "0f366eb3e9e2fcab52b8ebacd197db9047186a5f"
- resolution initialized to: "None"
- severity initialized to: "Minor"
- status initialized to: "Open"
- submitter initialized to: "oehhar"
- subsystem initialized to: "36. Pathname Management"
- title initialized to:
"glob -path a" core dumps instead of argument error
- type initialized to: "Bug"
Ticket change [dd72da17d2] (rid 146929) by dah on 2016-06-13 15:25:57:
- icomment:
I can confirm the crash. I can't reproduce it compiling with mingw gcc or gcc on linux. In func Tcl_GlobObjCmd in tclFileName.c it is hitting the "} else if (dir == PATH_GENERAL) {" branch and objc = 0 for Linux+Windows. Tcl_DString str isn't being initialized with MSVC. I guess gcc is doing some optimization trick where it does do the initialization (gdb shows the struct initialized.)? I don't understand assembly well enough to be able to see it myself. So it is doing a Tcl_DStringFree on a DString that was never initialized causing the crash. - login: "dah"
- mimetype: "text/plain"
- username: "dah"
- icomment:
Ticket change [9c26d88e76] (rid 146931) by dah on 2016-06-13 18:27:30:
- icomment:
I can't create a patch atm but here's a naive solution: In file tclFileName.c @ line 1569 skipTypes: /* * Now we perform the actual glob below. This may involve joining together * the pattern arguments, dealing with particular file types etc. We use a * 'goto' to ensure we free any memory allocated along the way. */ objc -= i; /* Fix crash due to not checking if glob pattern exists */ if (objc == 0) { Tcl_SetObjResult(interp, Tcl_NewStringObj("missing glob pattern", -1)); result = TCL_ERROR; Tcl_SetErrorCode(interp, "TCL", "ARGUMENT", "BAD", NULL); join = 0; goto endOfGlob; } objv += i; result = TCL_OK; - login: "dah"
- mimetype: "text/plain"
- username: "dah"
- icomment:
Ticket change [95bac0ca5f] (rid 146946) by dah on 2016-06-14 23:48:38:
- icomment:
Ok, in case anyone is interested, it doesn't crash when compiled with gcc due to an optimization where it reuses local variable storage. There is a DString "pref" initialization done before the code block triggering the crash with MSVC, and that same storage is reused later for DString "str" (with gcc). Below is essentially what is happening and shouldn't crash with gcc either, but does with MSVC: #include <tcl.h> #include <stdio.h> int main (int argc, char *argv[]) { if (1) { Tcl_DString one; Tcl_DStringInit(&one); Tcl_DStringFree(&one); } if (2) { /* Should crash, but gcc saves the day! two -> one */ Tcl_DString two; Tcl_DStringFree(&two); } } This isn't a Windows only bug, I suspect it will manifest itself with other compilers. - login: "dah"
- mimetype: "text/plain"
- username: "dah"
- icomment:
Ticket change [3b783d7141] (rid 146994) by dgp on 2016-06-16 18:22:01:
- icomment:
Can anyone explain how we reach "skipTypes:" with (objc == i) ?
- login: "dgp"
- mimetype: "text/plain"
- icomment:
Ticket change [8f0fe6021a] (rid 147007) by dgp on 2016-06-20 19:35:05:
- assignee changed to: "dgp"
- closedate changed to: "2457560.31603374"
- closer changed to: "dgp"
- icomment:
The 8.5 -> 8.6 difference is rooted in TIP 323. [glob] has been revised to accept zero pattern arguments. Proper behavior for [glob -path a] is now: no files matched glob patterns "" and [glob -nocomplain -path a] would succeed and return an empty list. A stanza of C code was written in a way that implicitly assumed 1 or more pattern arguments. Likely not on purpose. Just a misplaced initialization. Then as described, gcc quirks hid the consequences from a lot of us. Fixed for 8.6.6 and beyond.
- login: "dgp"
- mimetype: "text/plain"
- resolution changed to: "Fixed"
- status changed to: "Closed"