Skip to content
Tcl Source Code Artifact [9c97fffe7f]
Login

Artifact [9c97fffe7f]

Artifact 9c97fffe7f3a2f9eb51036666e2e8744fedb19743cde97133ebb8dd79831e3c1:

Ticket change [9c97fffe7f] - New ticket [8911644dc28094b0|8911644dc2] <i>clock: use-after-free when a callback clears the clock caches, and memory errors on malformed locale data</i>. by bef on 2026-11-13 20:05:37.
D 2026-11-13T20:05:37.753
J assignee nobody
J closer nobody
J cmimetype text/x-markdown
J comment Memory\serrors\sin\sthe\sC\sclock\sengine:\sa\suse-after-free\swhen\sa\scallback\sclears\sthe\sclock\scaches,\san\sout-of-bounds\sread\sand\sa\sdouble\sfree\sin\s`TclStrIdxTree`,\sand\sa\sNULL\sdereference\son\smalformed\slocale\sdata.\sThey\sneed\sa\sscript\sthat\sinstalls\sits\sown\scallbacks\sor\slocale\sdata;\soutside\sdata\sdoes\snot\sreach\sthem.\r\n\r\nAffected:\s9.0.4,\s9.1.0\sand\strunk\s(as\sof\s2026-11-13,\s[12c60e9c42](https://core.tcl-lang.org/tcl/info/12c60e9c42)).\s8.6\sis\snot\saffected,\sbecause\sits\sclock\sformatting\sand\sscanning\sare\sTcl\scode.\sAll\sPoCs\sbelow\sare\sfor\strunk.\sFixes\sfollow\sin\sa\scomment.\r\n\r\n**1.\sUse-after-free\swhen\sa\scallback\sclears\sthe\sclock\scaches\sduring\s`clock\sformat`\sor\s`clock\sscan`**\r\n\r\n`ClockLocalizeFormat`,\s`TclClockMCDict`\sand\sthe\sscan\sand\sformat\stoken\sloops\shold\sthe\slocale\scatalogue\s(`opts->mcDictObj`),\sthe\snormalised\slocale,\sthe\snormalised\stime\szone\s(`opts->timezoneObj`),\sthe\sformat\sstorage\sand\sthe\sclient\sdata\sby\splain\spointer\swhile\sthey\srun\sTcl\scallbacks\s(`LocalizeFormat`,\s`mcget`,\s`SetupTimeZone`,\s`TZData`\sreads).\sA\scallback\sthat\sruns\s`::tcl::unsupported::clock::configure\s-clear`\sor\s`::tcl::clock::ClearCaches`,\sor\sthat\sdeletes\sthe\sclock\scommands,\sfrees\sthem:\r\n\r\n\s\s\s\sclock\sformat\s0\s-gmt\s1\r\n\s\s\s\strace\sadd\svariable\s::tcl::clock::LocFmtMap\sread\s{apply\s{args\s{\r\n\s\s\s\s\s\s\s\s::tcl::unsupported::clock::configure\s-clear\r\n\s\s\s\s}}}\r\n\s\s\s\sclock\sformat\s0\s-format\s%x\s-locale\sfr\s-gmt\s1\r\n\r\n\s\s\s\sSUMMARY:\sAddressSanitizer:\sheap-use-after-free\stclClockFmt.c:951\sin\sClockLocalizeFormat\r\n\r\nThe\ssame\spattern\sgives\sa\sNULL\sdereference\sin\s`Tcl_DictObjPut`\sfrom\s`TclClockMCDict`\s(`tclClock.c:779`)\swith\sa\smsgcat\s`loadcmd`\sfor\s`::tcl::clock`.\sWith\sa\s`TZData`\sread\strace\sduring\s`clock\sscan\s...\s%Z`,\sit\sgives\sa\suse-after-free\sof\sthe\stoken\sarray\s(`tclClockFmt.c:2421`)\sor\sof\sthe\sclient\sdata\s(`tclClock.c:1324`).\sThe\stime\szone\sobject\sis\sfreed\sthe\ssame\sway\swhen\sonly\sthe\scaches\sown\sit,\swhich\sis\sthe\scase\sonce\san\sequal\szone\sname\shas\sbeen\sused\sbefore;\s`%Z`\sin\s`clock\sformat`\sand\sthe\sconversion\sat\sthe\send\sof\s`clock\sscan`\sthen\sread\sit\sin\s`ClockGetTZData`.\sTwo\ssmaller\sproblems\sare\sclose\sby:\s`TclClockMCDict`\suses\sthe\s`mcget`\sresult\safter\s`Tcl_ResetResult`,\sand\s`ClockLocalizeFormat`\sleaks\sa\ssmart\sreference.\r\n\r\n**2.\s`TclStrIdxTree`:\sout-of-bounds\sread\swith\sU+023A\sor\sU+023E\sin\slocale\snames,\sdouble\sfree\son\sallocation\sfailure**\r\n\r\n`TclStrIdxTreeBuildFromList`\slowers\skeys\swith\s`Tcl_UtfToLower`,\swhich\skeeps\sU+023A\sand\sU+023E\sbecause\stheir\slowercase\sforms\sneed\smore\sbytes.\sKeys\sthat\smatch\scase-insensitively\sthen\shave\sprefixes\sof\sdifferent\sbyte\slengths,\sand\s`TclStrIdxTreeSearch`\sapplies\san\soffset\smeasured\sin\sone\skey\sto\sits\ssiblings:\r\n\r\n\s\s\s\sclock\sformat\s0\s-gmt\s1\r\n\s\s\s\snamespace\seval\s::tcl::clock\s{\r\n\s\s\s\s\s\s\s\s::msgcat::mcset\sxx\sMONTHS_FULL\s[list\sⱥⱥy\sȺȺz\sMarch\sApril\sMay\sJune\sJuly\s\\\r\n\s\s\s\s\s\s\s\s\s\s\s\sAugust\sSeptember\sOctober\sNovember\sDecember]\r\n\s\s\s\s}\r\n\s\s\s\scatch\s{clock\sscan\s"ⱥⱥq\s2000"\s-format\s"%B\s%Y"\s-locale\sxx\s-gmt\s1}\r\n\r\n\s\s\s\sSUMMARY:\sAddressSanitizer:\sheap-buffer-overflow\stclStrIdxTree.h:130\sin\sTclUtfFindEqualNCInLwr\r\n\r\nNo\sshipped\s`msgs/*.msg`\sfile\scontains\sthese\scharacters.\sMatching\sis\swrong\sas\swell:\sinput\s`ⱥⱥz`\sdoes\snot\smatch\sthe\skey\s`ȺȺz`.\r\n\r\nOn\san\sallocation\sfailure,\s`TclStrIdxTreeBuildFromList`\sfrees\sthe\stree\sitems\sbut\sleaves\s`firstPtr`\sset.\sIts\scallers\s(`ClockMCGetListIdxTree`,\s`ClockMCGetMultiListIdxTree`)\sthen\sfree\sthe\sobject,\sand\sthe\sinternal-rep\sfree\sproc\sfrees\sthe\ssame\sitems\sagain.\r\n\r\n**3.\sNULL\sdereference\son\smalformed\s`LOCALE_ERAS`\sor\s`LOCALE_NUMERALS`,\sand\sformat\serrors\sthat\sare\sdropped\sor\shave\sno\smessage**\r\n\r\n`ClockFmtToken_LocaleERAYear_Proc`\sdoes\snot\scheck\sthe\sNULL\sthat\s`Tcl_ListObjIndex`\sreturns\sfor\sa\sshort\sera\srow\sor\sa\s`LOCALE_NUMERALS`\slist\sunder\s100\sentries:\r\n\r\n\s\s\s\sclock\sformat\s0\s-gmt\s1\r\n\s\s\s\snamespace\seval\s::tcl::clock\s{\r\n\s\s\s\s\s\s\s\s::msgcat::mcset\sxx\sLOCALE_ERAS\s{{-1000000000000}}\r\n\s\s\s\s}\r\n\s\s\s\sclock\sformat\s0\s-format\s%EC\s-locale\sxx\s-gmt\s1\r\n\r\n\s\s\s\stclClockFmt.c:3074:6:\sruntime\serror:\smember\saccess\swithin\snull\spointer\sof\stype\s'Tcl_Obj'\r\n\r\nRelated:\s`TclClockFormat`\sjumps\sto\s`done`\sinstead\sof\s`error`\swhen\sa\s`CTOKT_INT`\sformat\sprocedure\sfails,\sso\s`clock\sformat`\sreturns\sthe\soutput\sso\sfar\swith\s`TCL_OK`.\sWith\s`LOCALE_ERAS\s{{-1000000000000\sE\snotanumber}}`,\s`clock\sformat\s0\s-format\s"<%Ey>"`\sreturns\s`<`\s(8.6\sreports\sthe\serror).\r\n\r\nA\slist\sshorter\sthan\sthe\sformat\sneeds\sin\sthe\sother\slocale\slookups\sof\s`TclClockFormat`\s(`MONTHS_*`\sand\s`DAYS_OF_WEEK_*`,\sand\s`LOCALE_NUMERALS`\sfor\sthe\s`%O`\sconversions)\smakes\s`clock\sformat`\sfail\swith\san\sempty\serror\smessage\sand\serror\scode\s`NONE`.\sWith\s`MONTHS_ABBREV\s{a\sb}`,\s`clock\sformat\s1700000000\s-format\s%b\s-gmt\s1`\sfails\sthat\sway;\s8.6\sformats\san\sempty\sname.
J foundin 9.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 Important
J status Open
J submitter bef
J subsystem 16.\sCommands\sA-H
J title clock:\suse-after-free\swhen\sa\scallback\sclears\sthe\sclock\scaches,\sand\smemory\serrors\son\smalformed\slocale\sdata
J type Bug
K 8911644dc28094b08b47b20df766aeafc64ace7a
U bef
Z 86335bc2af19d5e15f3a662f44a19f5e