Skip to content
Tcl Source Code Artifact [a6bbf72641]
Login

Artifact [a6bbf72641]

Artifact a6bbf72641859ad311709ec9c55cd0527a9205ede90cc91c92d1811a8363469c:

Ticket change [a6bbf72641] - New ticket [39fed4dae51e4fd7|39fed4dae5] <i>Tcl_PkgRequireEx, Tcl_InitStubs broken in 8.6.9</i>. by edhume3 on 2019-02-27 18:19:46.
D 2019-02-27T18:19:46.751
J assignee nobody
J closer nobody
J cmimetype text/plain
J comment Apps\sthat\shave\scopied\sprevious\sversions\sof\stkMain.c\shave\schecked\sfor\san\sexact\sTcl\smatch\swith\scode\slike\sthis\searly\sin\sthe\sstartup:\r\n\r\nif\s(Tcl_InitStubs(interp,\sTCL_VERSION,\s1)\s==\sNULL)\s{\r\n\s\s\s\sabort();\r\n\s\s\s\s}\r\n\r\nIn\sTcl\s8.6.9\sthe\srequest\sfor\san\sexact\smatch\s(3rd\sargument\s=1)\sfails\swhen\sit\sshould\snot.\s\s\r\n\r\nThe\sproblem\sis\scaused\sby\schanges\sin\sTcl\s8.6.9\sTcl_PkgRequireEx()\sin\sgeneric/TclPkg.c.\s\sThe\slogic\sis\susing\sa\svolatile\sresult\sobtained\swith\sTcl_GetStringResult(),\sso\sthat\sthe\sreturn\svalue\sof\sTcl_PkgRequireEx()\sis\snot\sa\svalid\spointer.\s\sI\sverified\sthe\sissue\sby\sadding\sprintf\sstatements\sin\sthe\sflawed\scode\sand\ssaw\sthat\sthe\svalue\sreturned\sby\sTcl_PkgRequireProc()\swas\soverwritten\sinstead\sof\sbeing\sthe\sreturn\svalue\sof\sTcl_PkgRequireEx().\s\sThe\sproblem\scan\sbe\sseen\sby\sinspection\sif\sthe\sinspector\srealizes\sthat\sthe\sreturn\svalue\sof\sTcl_GetStringResult()\sis\svolatile\sand\sneeds\sto\sbe\scopied.\s\sA\sdemo\sfix\sthat\sis\snot\sthreadsafe,\swould\sbe\sto\sdeclare\sa\sstatic\sbuffer\sand\suse\sit\sto\scache\sthe\sreturn\svalue\slike\sthis:\r\n\r\nconst\schar\s*\r\nTcl_PkgRequireEx(\r\n\s\s\s\sTcl_Interp\s*interp,\t\t/*\sInterpreter\sin\swhich\spackage\sis\snow\r\n\t\t\t\t\s*\savailable.\s*/\r\n\s\s\s\sconst\schar\s*name,\t\t/*\sName\sof\sdesired\spackage.\s*/\r\n\s\s\s\sconst\schar\s*version,\t/*\sVersion\sstring\sfor\sdesired\sversion;\sNULL\r\n\t\t\t\t\s*\smeans\suse\sthe\slatest\sversion\savailable.\s*/\r\n\s\s\s\sint\sexact,\t\t\t/*\sNon-zero\smeans\sthat\sonly\sthe\sparticular\r\n\t\t\t\t\s*\sversion\sgiven\sis\sacceptable.\sZero\smeans\suse\r\n\t\t\t\t\s*\sthe\slatest\scompatible\sversion.\s*/\r\n\s\s\s\svoid\s*clientDataPtr)\t/*\sUsed\sto\sreturn\sthe\sclient\sdata\sfor\sthis\r\n\t\t\t\t\s*\spackage.\sIf\sit\sis\sNULL\sthen\sthe\sclient\sdata\r\n\t\t\t\t\s*\sis\snot\sreturned.\sThis\sis\sunchanged\sif\sthis\r\n\t\t\t\t\s*\scall\sfails\sfor\sany\sreason.\s*/\r\n{\r\n\s\s\s\sTcl_Obj\s*ov;\r\n\s\s\s\sstatic\schar\sresult[50];\s\s/*\sdemo\sfix\s*/\r\n...\r\n\r\n\s\s\s\s/*\r\n\s\s\s\s\s*\sTranslate\sbetween\sold\sand\snew\sAPI,\sand\sdefer\sto\sthe\snew\sfunction.\r\n\s\s\s\s\s*/\r\n\r\n\s\s\s\sif\s(version\s==\sNULL)\s{\r\n\tif\s(Tcl_PkgRequireProc(interp,\sname,\s0,\sNULL,\sclientDataPtr)\s==\sTCL_OK)\s{\r\n#if\s0\r\n\t\s\s\s\sresult\s=\sTcl_GetStringResult(interp);\r\n#else\r\n\s\s\s\s\s\s\s\s/*\snot\sthreadsafe\s-\sdemo\sfix\snot\sa\sreal\sfix\s*/\r\n\s\s\s\s\s\s\s\sstrncpy(result,\sTcl_GetStringResult(interp),\ssizeof(result)-1);\r\n\s\s\s\s\s\s\s\sresult[sizeof(result)-1]\s=\s0;\r\n#endif\r\n\t\s\s\s\sTcl_ResetResult(interp);\r\n\t}\r\n\s\s\s\s}\selse\s{\r\n\tif\s(exact\s&&\sTCL_OK\r\n\t\t!=\sCheckVersionAndConvert(interp,\sversion,\sNULL,\sNULL))\s{\r\n\t\s\s\s\sreturn\sNULL;\r\n\t}\r\n\tov\s=\sTcl_NewStringObj(version,\s-1);\r\n\tif\s(exact)\s{\r\n\t\s\s\s\sTcl_AppendStringsToObj(ov,\s"-",\sversion,\sNULL);\r\n\t}\r\n\tTcl_IncrRefCount(ov);\r\n\tif\s(Tcl_PkgRequireProc(interp,\sname,\s1,\s&ov,\sclientDataPtr)\s==\sTCL_OK)\s{\r\n#if\s0\r\n\t\s\s\s\sresult\s=\sTcl_GetStringResult(interp);\r\n#else\r\n\s\s\s\s\s\s\s\s/*\snot\sthreadsafe\s-\sdemo\sfix\snot\sa\sreal\sfix\s*/\r\n\s\s\s\s\s\s\s\sstrncpy(result,\sTcl_GetStringResult(interp),\ssizeof(result)-1);\r\n\s\s\s\s\s\s\s\sresult[sizeof(result)-1]\s=\s0;\r\n#endif\r\n//printf("result=%s\\n",\sresult);\s"8.6.9"\r\n\t\s\s\s\sTcl_ResetResult(interp);\r\n\t}\r\n\tTclDecrRefCount(ov);\r\n\s\s\s\s}\r\n//printf("result=%s\\n",\sresult);\s""\s\r\n\s\s\s\sreturn\sresult;\r\n}\r\n\r\nThe\sproblem\slikely\ssurfaces\sfor\smost\spackage\srequire\sAPI\scalls\sthat\sseek\san\sexact\smatch.
J foundin 8.6.9
J is_private 0
J login edhume3
J priority 5\sMedium
J private_contact 6f627129970c8eb5cdc6ce33f57dfc0c27196d8d
J resolution None
J severity Important
J status Open
J submitter edhume3
J subsystem 39.\sPackage\sManager
J title Tcl_PkgRequireEx,\sTcl_InitStubs\sbroken\sin\s8.6.9
J type Bug
K 39fed4dae51e4fd7f1abf6baf3ba094a072b8beb
U edhume3
Z ea9ad8c5dfc6d27139fa06e7590c5fba