Skip to content
Tcl Source Code Artifact [8a1e1f5698]
Login

Artifact [8a1e1f5698]

Artifact 8a1e1f56982eaa0d2aa5540e1ccaf4ed2026356ed710d3afae74e59850bc42b0:

Ticket change [8a1e1f5698] - New ticket [813699148d191774|813699148d] <i>Heap out-of-bounds read and NULL dereference in `clock` on malformed `TZData`</i>. by bef on 2026-11-05 14:33:49.
D 2026-11-05T14:33:49.692
J assignee nobody
J closer nobody
J cmimetype text/x-markdown
J comment Security\sissue:\smemory\scorruption\sthat\sa\sscript\sin\sa\ssafe\sinterpreter\scan\strigger\son\strunk\sand\sin\severy\srelease,\sand\sthat\sany\strusted\sscript\scan\strigger\severywhere.\sThe\sC\sclock\scode\stakes\sthe\srows\sof\s`::tcl::clock::TZData`\sas\sthey\sare\sand\sindexes\sinto\sthem\swithout\schecking\stheir\slength.\sA\srow\swith\sfewer\sthan\sfour\selements\smakes\sit\sread\sa\s`Tcl_Obj\s*`\spast\sthe\send\sof\sthe\slist's\selement\sarray,\sand\sthen\sincrement\sthat\sobject's\sreference\scount\sand\suse\sit\sas\sthe\stime\szone\sname.\sAn\sempty\srow\sgives\sa\sNULL\sdereference.\r\n\r\nAll\sthree\sPoCs\sbelow\srun\sin\sa\splain\s`tclsh`.\sThe\sfirst\sline\sloads\sthe\sTcl\spart\sof\s`clock`\s(needed\son\s8.6,\sharmless\son\s9.x).\r\n\r\n1.\s**UTC\sto\slocal.**\s`ConvertUTCToLocalUsingTable`\sreads\s`cellv[3]`\s(and\s`cellv[1]`\sfor\sa\s1-element\srow)\swithout\schecking\s`cellc`:\r\n\r\n\s\s\s\s\s\s\s\sclock\sformat\s0\s-gmt\s1\r\n\s\s\s\s\s\s\s\sset\s::tcl::clock::TZData(:bad)\s{{0\s0}}\r\n\s\s\s\s\s\s\s\sclock\sformat\s10\s-timezone\s:bad\r\n\r\n\s\s\s\sASan\son\strunk:\r\n\r\n\s\s\s\s\s\s\s\sREAD\sof\ssize\s8\s...\sis\slocated\s8\sbytes\safter\s56-byte\sregion\r\n\s\s\s\s\s\s\s\sSUMMARY:\sAddressSanitizer:\sheap-buffer-overflow\stclClock.c:2307\sin\sConvertUTCToLocalUsingTable\r\n\r\n\s\s\s\sThe\ssame\shappens\son\s9.1.0\s(line\s2307),\s9.0.4\sand\score-9-0-branch\s(2316),\s8.6.18\sand\score-8-6-branch\s(1023).\sWith\s`{0}`\sas\sthe\srow,\sthe\sread\sis\s`cellv[1]`,\spassed\sto\s`TclGetIntFromObj`\s(line\s2299\son\strunk,\s1015\son\s8.6).\r\n\r\n2.\s**Local\sto\sUTC**\s(9.0\sand\slater).\s`ConvertLocalToUTCUsingTable`\shas\sthe\ssame\s`cellv[3]`\sread.\s`clock\sscan`\sgets\sthere\swhen\sthe\sscanned\stime\sfalls\sinto\sthe\sshort\srow:\r\n\r\n\s\s\s\s\s\s\s\sclock\sformat\s0\s-gmt\s1\r\n\s\s\s\s\s\s\s\sset\s::tcl::clock::TZData(:bad)\s{{-9223372036854775808\s0\s0\sA}\s{100000\s0}}\r\n\s\s\s\s\s\s\s\sclock\sscan\s"1970-01-03\s00:00:00"\s-format\s"%Y-%m-%d\s%T"\s-base\s10\s-timezone\s:bad\r\n\r\n\s\s\s\s\s\s\s\sSUMMARY:\sAddressSanitizer:\sheap-buffer-overflow\stclClock.c:2043\sin\sConvertLocalToUTCUsingTable\r\n\r\n\s\s\s\sLine\s2052\son\s9.0.4\sand\score-9-0-branch.\sA\s1-element\srow\smakes\sit\sread\s`cellv[1]`\spast\sthe\sarray\s(line\s2031),\son\s8.6\sas\swell\s(line\s826);\s8.6\shas\sno\s`cellv[3]`\sread\shere.\r\n\r\n3.\s**Empty\srow.**\s`TclClockLookupLastTransition`\s(`LookupLastTransition`\son\s8.6)\stakes\selement\s0\sof\sa\srow\swith\s`Tcl_ListObjIndex`,\swhich\sreturns\sNULL\sfor\san\sempty\slist,\sand\spasses\sit\son\sto\s`TclGetWideIntFromObj`:\r\n\r\n\s\s\s\s\s\s\s\sclock\sformat\s0\s-gmt\s1\r\n\s\s\s\s\s\s\s\sset\s::tcl::clock::TZData(:bad)\s{{}}\r\n\s\s\s\s\s\s\s\sclock\sformat\s10\s-timezone\s:bad\r\n\r\n\s\s\s\s\s\s\s\stclClock.c:2435:9:\sruntime\serror:\smember\saccess\swithin\snull\spointer\sof\stype\s'Tcl_Obj'\r\n\r\n\s\s\s\sLine\s2444\son\s9.0.4,\s1153\son\s8.6.\sThis\sone\sis\sonly\sa\scrash.\r\n\r\nThe\sstray\spointer\sin\s1\sand\s2\sis\smore\sthan\sa\sread:\sit\sgets\sa\sreference\scount\sincrement,\sis\sstored\sin\sthe\sconversion\scache\sand\sin\sthe\sresult,\sand\sis\sread\sas\sa\sstring,\sso\swhatever\sobject\sor\sdata\sit\spoints\sto\sis\swritten\sto\sand\smay\slater\sbe\sfreed.\sWith\sthe\snormal\sallocator\sthe\sslot\spast\sa\ssmall\slist\susually\slies\sinside\sthe\ssame\sallocator\sblock\sand\sholds\sleftover\sdata\sfrom\san\searlier\suse.\sIn\sone\srun\son\san\soptimised\strunk\sbuild\sit\sheld\sstring\sbytes\s(`0x206d756e67695364`),\sand\sthe\sscript\shas\sa\slot\sof\sinfluence\sover\swhat\sis\sleft\sthere.\sWithout\ssanitisers\sall\sthree\sPoCs\send\sin\sa\ssegmentation\sfault\son\s9.1.0\sand\strunk.\r\n\r\n**Exploitability.**\sItems\s1\sand\s2\sare\sassessed\sas\splausibly\sexploitable\sfor\scode\sexecution,\sgiven\san\saddress\sleak\sor\sheap\spredictability.\sNo\sexploit\shas\sbeen\swritten.\sItem\s3\sis\sa\sdenial\sof\sservice\sonly.\r\n\r\nIn\sa\ssafe\sinterpreter\s`clock`\sis\san\salias\sto\sthe\sparent's,\sso\sthe\schild's\sown\s`TZData`\sdoes\snot\sreach\sit\sthat\sway.\sBut\son\strunk\sand\sin\sall\sreleases\sthe\s`::tcl::clock::*`\shelpers\sare\svisible\sin\ssafe\sinterps,\sand\sthese\stake\sthe\schild's\sown\s`TZData`:\r\n\r\n\s\s\s\sinterp\seval\s[interp\screate\s-safe]\s{\r\n\s\s\s\s\s\s\s\sset\s::tcl::clock::TZData(:bad)\s{{0\s0}}\r\n\s\s\s\s\s\s\s\s::tcl::clock::GetDateFields\s10\s:bad\s2361222\r\n\s\s\s\s}\r\n\r\nThis\sgives\sthe\ssame\sreport\sas\s1\son\strunk,\s9.1.0\sand\s9.0.4\s(on\s8.6\sthe\shelpers\stake\sthe\srows\sthemselves\sinstead\sof\sa\sname,\swith\sthe\ssame\sresult).\r\n\r\nThe\shelpers\sshould\snot\sbe\svisible\sthere\sat\sall.\s`TclClockInit`\screates\sthem\sfrom\s`Tcl_CreateInterp`\sand\sskips\sthem\sonly\sif\s`Tcl_IsSafe(interp)`\sis\strue,\sbut\sa\ssafe\schild\sis\sonly\smarked\ssafe\sby\s`MakeSafe`,\safter\s`Tcl_CreateInterp`\shas\sreturned.\sSo\severy\ssafe\sinterp\sgets\sthem,\sand\sthe\ssame\sgap\slets\sit\sread\sany\senvironment\svariable\sof\sthe\sprocess\sthrough\s`::tcl::clock::getenv`.\sBoth\smaintenance\sbranches\shave\sfixed\sthis:\score-8-6-branch\screates\sthe\schild\sas\ssafe\sfrom\sthe\sstart\s([940c0e06e1](https://core.tcl-lang.org/tcl/info/940c0e06e1)),\sand\score-9-0-branch\smoves\s`TclClockInit`\sto\s`Tcl_Init`,\swhich\sa\ssafe\schild\snever\sruns,\sand\sreverts\s[2316f673af](https://core.tcl-lang.org/tcl/info/2316f673af)\s([a94e95399a](https://core.tcl-lang.org/tcl/info/a94e95399a)).\sNeither\sfix\sis\son\strunk\s(both\sreached\sit\sonly\sthrough\smerges\swithout\scontent)\sor\sin\sa\srelease.\sThe\srecommended\sfix\sis\sto\sbring\sone\sof\sthem\sto\strunk,\stogether\swith\sthe\srevert\sof\s[2316f673af](https://core.tcl-lang.org/tcl/info/2316f673af),\sand\sto\srelease\s8.6.x\sand\s9.0.x\swith\sthem.\sThat\sstops\ssafe\sinterps\sfrom\sreaching\sthe\sbug\sin\sthis\sticket,\sbut\sit\sdoes\snot\sfix\sthe\sbug\sitself:\strusted\sscripts\sstill\strigger\sit\son\severy\sbranch,\sso\sthe\schecks\sbelow\sare\sneeded\sas\swell.\r\n\r\nThe\sreads\sgo\sback\sto\sthe\sC\sclock\scode\sof\s8.5.0\s(2005),\sexcept\sthe\s`cellv[3]`\sread\sin\slocal\sto\sUTC,\swhich\scame\swith\sthe\sclock\srewrite\sin\s9.0.\r\n\r\n**Fix\ssuggestion.**\sIn\s`ConvertUTCToLocalUsingTable`\sand\s`ConvertLocalToUTCUsingTable`,\swhich\sread\s`cellv[1]`\sand\s`cellv[3]`,\scheck\s`cellc\s>=\s4`\safter\s`TclListObjGetElements`\sand\sreturn\san\serror\ssuch\sas\s"malformed\stime\szone\sdata"\sotherwise.\sIn\s`TclClockLookupLastTransition`,\streat\s`compObj\s==\sNULL`\sfrom\seither\s`Tcl_ListObjIndex`\scall\s(first\srow\sand\sbinary\ssearch)\sas\sthe\ssame\serror.\s8.6\sneeds\sthe\ssame\schecks\sin\sits\sversions\sof\sthe\sthree\sfunctions.\sChecking\seach\srow\sonce\swhere\s`TZData`\sis\sfetched\swould\scover\severy\suser\sof\sthe\stable,\sat\ssome\scost\sper\slookup.
J foundin 8.6.18,\s9.0.4,\s9.1.0,\s9.1.1\strunk
J is_private 0
J login bef
J priority 5\sMedium
J private_contact 37918056d323dc69a2f76cecc85476189094f3b8
J resolution None
J severity Severe
J status Open
J submitter bef
J subsystem 16.\sCommands\sA-H
J title Heap\sout-of-bounds\sread\sand\sNULL\sdereference\sin\s`clock`\son\smalformed\s`TZData`
J type Bug
K 813699148d19177469c94023f3dc739cbd2d9f8d
U bef
Z 5b0f9b43a302449453e87fa07e787b47