Skip to content
Tcl Source Code Artifact [a3963ccbe8]
Login

Artifact [a3963ccbe8]

Artifact a3963ccbe82fe604431dad5dcf3951c458d32887900b5456577bd782cc35ad14:

Ticket change [a3963ccbe8] - New ticket [f2ff05fc8411be80|f2ff05fc84] <i>Usage of static systemEncoding is not thread safe (vulnerability)</i>. by sebres on 2021-04-06 16:14:12.
D 2021-04-06T16:14:12.018
J assignee nobody
J closer nobody
J cmimetype text/x-fossil-wiki
J comment <code>Tcl_UtfToExternal*</code>,\s<code>Tcl_ExternalToUtf*</code>\s(et\sal.)\shave\sa\scertain\sweakness\sif\sused\swith\sNULL\s(system-encoding).\s\r\nIf\sfor\ssome\sreason\ssystemEncoding\sis\sa\ssingle\sreference\s(used\sonly\sonce),\sit\swill\sbe\sused\sin\sthat\sfunctions\swithout\sto\stouch\sits\srefCount,\sso\sif\sanother\sthread\ssets\sit\sto\sdifferent\svalue\s-\sit\scould\ssegfault\sinside\sconversion\sif\sthis\sprevious\ssystem\sencoding\sgets\sfreed.\r\n\r\nI\sknow\sthat\snormally\sthe\schange\sof\ssystem\sencoding\sis\seither\srare\scase,\sbut\sa\svulnerability\sremains\svulnerability...\r\n\r\nAtomic\sincr/decr\sof\sits\srefCount\smay\shelp\shere...\s\r\nBut\scurrently\s(without\sto\shave\ssuch\satomic\sfacilities)\sit\swould\simply\sto\suse\smutex,\sand\sit\swould\sbe\sugly\sby\seach\sconversion\s(would\sprovide\sa\smulti-threaded\sbottleneck,\seven\stwice\sby\sstart\sand\send\sof\sconvert-routines).\r\n\r\nAs\sfor\satomic\sfacilities,\sI\smade\ssome\sfor\sanother\sissue\s-\sfor\sexample\ssee\s[https://github.com/sebres/tcl/blob/1e522ffa06a7aca2fd729e709ffdccb4f56b6882/generic/tclInt.h#L131|sebres/tcl/1e522ff/tclInt.h#L131].\r\n\r\nSimplest\sscenario\sto\sreproduce\sthe\sSF\s(for\sunderstanding):\r\n<code><pre\sstyle="margin-left:15pt">\r\nTcl_SetSystemEncoding(NULL,\s"enc1");\r\n...\sthread::create\s{\sencoding\sconvertfrom\s[string\srepeat\s"..."\s$Some_Large_N]\s};\s\r\nTcl_SetSystemEncoding(NULL,\s"enc2");\s\r\n//\sBOOM\sin\shelper\sthread\s(if\s2nd\sset\stakes\splace\sduring\sconvertfrom\sprocess\sand\s"enc1"\sis\sunused\selsewhere)...\r\n</pre></code>
J foundin any
J is_private 0
J login sebres
J priority 5\sMedium
J resolution None
J severity Critical
J status Open
J submitter sebres
J subsystem 11.\sConversions\sfrom\sString
J title Usage\sof\sstatic\ssystemEncoding\sis\snot\sthread\ssafe\s(vulnerability)
J type Bug
K f2ff05fc8411be80a93913b2b065f2c85fa9bcf0
U sebres
Z bd98a6f310393cba20226b3d14db26da