Overview
| Artifact ID: | a6bbf72641859ad311709ec9c55cd0527a9205ede90cc91c92d1811a8363469c |
|---|---|
| Ticket: | 39fed4dae51e4fd7f1abf6baf3ba094a072b8beb
Tcl_PkgRequireEx, Tcl_InitStubs broken in 8.6.9 |
| User & Date: | edhume3 on 2019-02-27 18:19:46 |
Changes
- assignee changed to: "nobody"
- closer changed to: "nobody"
- cmimetype changed to: "text/plain"
- comment changed to:
Apps that have copied previous versions of tkMain.c have checked for an exact Tcl match with code like this early in the startup: if (Tcl_InitStubs(interp, TCL_VERSION, 1) == NULL) { abort(); } In Tcl 8.6.9 the request for an exact match (3rd argument =1) fails when it should not. The problem is caused by changes in Tcl 8.6.9 Tcl_PkgRequireEx() in generic/TclPkg.c. The logic is using a volatile result obtained with Tcl_GetStringResult(), so that the return value of Tcl_PkgRequireEx() is not a valid pointer. I verified the issue by adding printf statements in the flawed code and saw that the value returned by Tcl_PkgRequireProc() was overwritten instead of being the return value of Tcl_PkgRequireEx(). The problem can be seen by inspection if the inspector realizes that the return value of Tcl_GetStringResult() is volatile and needs to be copied. A demo fix that is not threadsafe, would be to declare a static buffer and use it to cache the return value like this: const char * Tcl_PkgRequireEx( Tcl_Interp *interp, /* Interpreter in which package is now * available. */ const char *name, /* Name of desired package. */ const char *version, /* Version string for desired version; NULL * means use the latest version available. */ int exact, /* Non-zero means that only the particular * version given is acceptable. Zero means use * the latest compatible version. */ void *clientDataPtr) /* Used to return the client data for this * package. If it is NULL then the client data * is not returned. This is unchanged if this * call fails for any reason. */ { Tcl_Obj *ov; static char result[50]; /* demo fix */ ... /* * Translate between old and new API, and defer to the new function. */ if (version == NULL) { if (Tcl_PkgRequireProc(interp, name, 0, NULL, clientDataPtr) == TCL_OK) { #if 0 result = Tcl_GetStringResult(interp); #else /* not threadsafe - demo fix not a real fix */ strncpy(result, Tcl_GetStringResult(interp), sizeof(result)-1); result[sizeof(result)-1] = 0; #endif Tcl_ResetResult(interp); } } else { if (exact && TCL_OK != CheckVersionAndConvert(interp, version, NULL, NULL)) { return NULL; } ov = Tcl_NewStringObj(version, -1); if (exact) { Tcl_AppendStringsToObj(ov, "-", version, NULL); } Tcl_IncrRefCount(ov); if (Tcl_PkgRequireProc(interp, name, 1, &ov, clientDataPtr) == TCL_OK) { #if 0 result = Tcl_GetStringResult(interp); #else /* not threadsafe - demo fix not a real fix */ strncpy(result, Tcl_GetStringResult(interp), sizeof(result)-1); result[sizeof(result)-1] = 0; #endif //printf("result=%s\n", result); "8.6.9" Tcl_ResetResult(interp); } TclDecrRefCount(ov); } //printf("result=%s\n", result); "" return result; } The problem likely surfaces for most package require API calls that seek an exact match. - foundin changed to: "8.6.9"
- is_private changed to: "0"
- login: "edhume3"
- priority changed to: "5 Medium"
- private_contact changed to: "6f627129970c8eb5cdc6ce33f57dfc0c27196d8d"
- resolution changed to: "None"
- severity changed to: "Important"
- status changed to: "Open"
- submitter changed to: "edhume3"
- subsystem changed to: "39. Package Manager"
- title changed to: "Tcl_PkgRequireEx, Tcl_InitStubs broken in 8.6.9"
- type changed to: "Bug"