<i>clock: use-after-free when a callback clears the clock caches, and memory errors on malformed locale data</i> status still Open with 3 other changes
by
.
D 2026-11-13T20:17:54.279
J icomment Fixes\son\sbranch\s[bug-891164-clock-memory-errors](/info/bug-891164-clock-memory-errors).\r\n\r\nEach\sfix\sis\sits\sown\scommit,\sso\sthat\sit\scan\sbe\spicked\sto\sother\sbranches\son\sits\sown;\sthe\scommits\sdo\snot\sdepend\son\seach\sother.\sThe\sfixes\sare\sfor\s9.x\sonly;\s8.6\sis\snot\schanged.\sTests\sare\sin\s`tests/clock.test`\s(new\sgroups\s`clock-81`\sand\s`clock-82`,\sto\sbe\srenumbered\sas\syou\slike).\r\n\r\n**Item\s1**\s(commit\s01).\sReferences\sare\staken\sfor\sthe\sduration\sof\seach\scommand\son\sthe\scatalogue,\sthe\slocale,\sthe\stime\szone,\sthe\sclient\sdata\sand\sthe\sformat\sstorage,\sand\sreleased\sin\sa\snew\s`ClockFreeFmtScnArgs`.\sThe\stime\szone\sis\sset\sthrough\sa\snew\s`ClockSetOptsTimezone`,\salso\swhere\s`clock\sscan`\schanges\sit\s(`%Z`,\sand\sa\szone\sin\sfree-form\sinput).\sWrites\sto\sa\sshared\scatalogue\snow\sgo\sthrough\sa\stemporary\ssmart\sreference\s(`TclClockMCDictPut`).\sThe\scommit\salso\sfixes\sthe\s`mcget`\sresult\sused\safter\s`Tcl_ResetResult`\sand\sthe\sleaked\ssmart\sreference.\sOne\scase\sis\sleft:\sa\scallback\sthat\sedits\s`::tcl::clock::mcMergedCat`\sin\splace\scan\sstill\schange\scatalogue\svalues\sthat\sC\sholds\sby\spointer.\sTests\s`clock-82.1`\sto\s`clock-82.6`,\seach\sin\sa\schild\sinterpreter.\r\n\r\n**Item\s2**\s(commits\s02,\s03).\sCommit\s02\sbuilds\sthe\skeys\slowercased\scharacter\sby\scharacter\swith\s`Tcl_UniCharToLower`.\sKeys\swithout\sU+023A\sor\sU+023E\scome\sout\sbyte\sfor\sbyte\sas\sbefore.\sTest\s`clock-82.7`\sfails\sby\sresult\seven\swithout\sa\ssanitiser.\sCommit\s03\sresets\s`firstPtr`\sand\s`lastPtr`\safter\sfreeing\sthe\sitems.\sNo\stest,\ssince\sthe\ssuite\scannot\smake\san\sallocation\sfail.\r\n\r\n**Item\s3**\s(commit\s04).\sNULL\schecks\swith\sthe\serror\s"malformed\slocale\sdata"\s(`CLOCK\smalformedLocaleData`,\smodelled\son\s`malformedTimeZoneData`),\sand\sthe\s`goto\sdone`\sbecomes\s`goto\serror`.\sThe\ssame\serror\sreplaces\sthe\sempty\smessage\sfor\sshort\s`MONTHS_*`,\s`DAYS_OF_WEEK_*`\sand\s`LOCALE_NUMERALS`\slists\sin\s`TclClockFormat`.\sThe\smessage\sand\serror\scode\sare\sonly\sa\ssuggestion.\sA\squiet\sfallback\s(plain\sdigits\sfor\sa\sshort\s`LOCALE_NUMERALS`\slist,\san\sempty\sname\sas\sin\s8.6)\swould\salso\sdo.\sTests\s`clock-81.1`\sto\s`clock-81.4`,\s`clock-81.8`,\s`clock-81.9`.\r\n\r\n**Test\sruns**\r\n\r\nThe\sfour\scommits\son\sthe\sbranch\s(from\strunk\s12c60e9c42)\swere\stested\swith\sASan\sand\sUBSan,\swith\sUBSan's\spointer-overflow\scheck\son:\r\n-\s`clock.test`:\s8783\stests,\s0\sfailed,\sno\ssanitiser\sreport.\r\n-\s`clock-ivm.test`,\s`msgcat.test`,\s`safe.test`\sand\s`safe-stock.test`:\sno\sfailures\sand\sno\ssanitiser\sreports.\r\n\r\nThey\swere\salso\srun\son\sa\sTCL_MEM_DEBUG\sbuild.\s`clock.test`\spasses\sthere.\sOver\s12000\srounds\sof\s`clock\sformat`,\s`scan`\sand\s`add`\sin\sthree\slocales,\smemory\sstays\sflat\swhen\sthe\scaches\sare\scleared\sbetween\srounds.\sWithout\sclearing,\sit\sgrows\sby\sexactly\sas\smuch\sas\sunpatched\strunk\sdoes\sover\sthe\ssame\srounds,\sso\sthe\snew\sreferences\sbalance.
J login bef
J mimetype text/x-markdown
K 8911644dc28094b08b47b20df766aeafc64ace7a
U bef
Z 98b9d309a2e09d4efbb74c93a317cebf