.
D 2026-11-05T16:16:49.001
J assignee nobody
J closer nobody
J cmimetype text/x-markdown
J comment Security\sissue:\sa\sstack\sbuffer\soverflow\sthat\sa\sscript\sin\sa\ssafe\sinterpreter\scan\strigger\sthrough\sthe\s`clock`\salias,\son\strunk\sand\sin\severy\s9.x\srelease.\sIt\salso\saffects\sany\sapplication\sthat\spasses\sa\stime\szone\sfrom\soutside\sdata\sto\s`clock\sformat`.\s8.6\sis\snot\saffected.\r\n\r\n`ClockFmtToken_TimeZone_Proc`\sreserves\sroom\sfor\s7\scharacters\sfor\s`%z`\s(`FrmResultAllocate(dateFmt,\s7)`,\s`tclClockFmt.c:2931`),\swhich\sis\senough\sfor\s`+hhmmss`.\sThe\shours\sare\sprinted\sby\s`Clock_itoaw`\swith\sa\sminimum\swidth\sof\s2\sbut\sno\smaximum,\sso\san\soffset\sof\s100\shours\sor\smore\sprints\smore\sdigits\sthan\swere\sreserved,\sand\sthe\sterminating\sNUL\sand\spossibly\ssome\sdigits\sland\spast\sthe\send\sof\sthe\sresult\sbuffer.\sThe\sresult\sbuffer\sis\sthe\s80-byte\sarray\s`resMem`\son\sthe\sstack\sof\s`TclClockFormat`\sfor\severy\scall\swhose\soutput\sfits\sin\s80\sbytes,\sand\sa\sheap\sblock\sotherwise.\r\n\r\nAll\sPoCs\srun\sin\sa\splain\s`tclsh`.\r\n\r\n1.\s**Fixed\soffset.**\sThe\sfixed-offset\spattern\sin\s`clock.tcl`\s(`^([-+])(\\d\\d)(?::?(\\d\\d)(?::?(\\d\\d))?)?`)\sdoes\snot\srange-check\sminutes\sor\sseconds,\sso\s`+99:99:99`\sis\saccepted\sas\s100\shours,\s40\sminutes\sand\s39\sseconds\sand\sprinted\sas\s`+1004039`.\sWith\s72\sbytes\sof\soutput\sbefore\sit,\sthe\sNUL\slands\sone\sbyte\spast\s`resMem`:\r\n\r\n\s\s\s\s\s\s\s\sclock\sformat\s0\s-timezone\s+99:99:99\s-format\s"[string\srepeat\sa\s72]%z"\r\n\r\n\s\s\s\sASan\son\strunk:\r\n\r\n\s\s\s\s\s\s\s\sWRITE\sof\ssize\s1\s...\soverflows\svariable\s'resMem'\s(line\s3399)\r\n\s\s\s\s\s\s\s\s#0\sClock_itoaw\stclClockFmt.c:230\r\n\s\s\s\s\s\s\s\s#1\sClockFmtToken_TimeZone_Proc\stclClockFmt.c:2940\r\n\s\s\s\s\s\s\s\s#2\sTclClockFormat\stclClockFmt.c:3504\r\n\s\s\s\s\s\s\s\sSUMMARY:\sAddressSanitizer:\sstack-buffer-overflow\stclClockFmt.c:230\sin\sClock_itoaw\r\n\r\n\s\s\s\sThe\ssame\son\s9.1.0\s(line\s230)\sand\s9.0.4\s(line\s234).\sPOSIX\srules\ssuch\sas\s`ABC-99:99:99`\sgive\sthe\ssame\soffset.\sTwo-digit\sfields\slimit\sthis\spath\sto\sexactly\sone\sNUL\sbyte.\sWith\smore\soutput\sbefore\s`%z`,\sso\sthat\sthe\sbuffer\shas\sbeen\smoved\sto\sthe\sheap,\sthe\ssame\sbyte\slands\sone\sbyte\spast\sthe\sheap\sblock\s(`heap-buffer-overflow`,\s"0\sbytes\safter\s260-byte\sregion"\swith\s`-format\s"[string\srepeat\sa\s100]%Y[string\srepeat\sb\s148]%z"`).\sIn\sthat\scase\s`TclClockFormat`\salso\swrites\sthe\sterminator\spast\sthe\sblock\sa\ssecond\stime\s(line\s3559)\sand\skeeps\sthe\sblock\sas\sthe\sstring\sof\sthe\sresult.\r\n\r\n2.\s**Offsets\sfrom\s`TZData`.**\sThe\soffset\sof\sa\stime\szone\stable\scan\sbe\sany\s32-bit\svalue.\sFor\sa\stable\sset\sby\sa\sscript,\sthe\slargest\soffset\sprints\sas\s`+5965231407`,\s11\scharacters\splus\sthe\sNUL\sagainst\s8\sreserved,\sso\sup\sto\sfour\sbytes\sof\sdigits\sand\sthe\sNUL\sare\swritten\spast\sthe\sbuffer:\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(:big)\s{{-9223372036854775808\s2000000000\s0\sBIG}}\r\n\s\s\s\s\s\s\s\sclock\sformat\s0\s-timezone\s:big\s-format\s"[string\srepeat\sa\s72]%z"\r\n\r\n\s\s\s\s\s\s\s\sSUMMARY:\sAddressSanitizer:\sstack-buffer-overflow\stclClockFmt.c:230\sin\sClock_itoaw\r\n\r\n\s\s\s\sSame\slines\sas\sitem\s1\son\s9.1.0\sand\s9.0.4.\sAn\soffset\sof\s`-2147483648`\sadditionally\shits\sundefined\sbehaviour\sin\s`z\s=\s-z`\s(line\s2928,\s2930\son\s9.0.4):\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(:min)\s{{-9223372036854775808\s-2147483648\s0\sMIN}}\r\n\s\s\s\s\s\s\s\sclock\sformat\s0\s-timezone\s:min\s-format\s%z\r\n\r\n\s\s\s\s\s\s\s\stclClockFmt.c:2928:10:\sruntime\serror:\snegation\sof\s-2147483648\scannot\sbe\srepresented\sin\stype\s'int'\r\n\r\n\s\s\s\sZoneinfo\sfiles\scarry\stheir\soffsets\sas\s32-bit\svalues\stoo;\swhether\s`clock.tcl`\schecks\sthem\son\sloading\swas\snot\slooked\sat.\r\n\r\nFrom\sa\ssafe\sinterpreter,\sitem\s1\sworks\sunchanged,\ssince\s`clock`\sthere\sis\san\salias\sto\sthe\sparent's\s`clock`,\swhich\sruns\s`ClockFormat`\sin\sthe\sparent:\r\n\r\n\s\s\s\sinterp\seval\s[interp\screate\s-safe]\s{\r\n\s\s\s\s\s\s\s\sclock\sformat\s0\s-timezone\s+99:99:99\s-format\s"[string\srepeat\sa\s72]%z"\r\n\s\s\s\s}\r\n\r\nThis\sgives\sthe\ssame\sASan\sreport\sas\sitem\s1,\sthrough\s`TclAliasObjCmd`,\son\strunk,\s9.1.0\sand\s9.0.4,\sand\swith\s`::safe::interpCreate`\sas\swell.\r\n\r\n**Effect\swithout\ssanitisers.**\sOn\smacOS\sarm64\sthe\sstack\sprotector's\scanary\ssits\sdirectly\safter\s`resMem`,\sso\sthe\soverwritten\sbyte\sis\sin\sthe\scanary\sand\sthe\sprocess\saborts\swith\s"stack\sbuffer\soverflow"\s(`__stack_chk_fail`).\sAll\sthree\sPoCs\sabove\sabort\sthe\sstock\s`tclsh`\s9.1.0\sfrom\sHomebrew\sthis\sway.\sA\ssafe\schild\scan\stherefore\stake\sdown\sthe\swhole\sprocess,\sincluding\sthe\sparent\sand\severy\sother\sinterpreter\sin\sit.\sWhere\sthe\scanary's\slowest\sbyte\sis\salready\szero\s(glibc)\sor\sthere\sis\sno\sstack\sprotector,\sa\ssingle\sNUL\smay\sgo\sunnoticed\sor\soverwrite\swhatever\sthe\scompiler\splaced\safter\s`resMem`.\sThe\smulti-byte\soverflow\sof\sitem\s2\sgoes\sfurther\sthan\sthat.\r\n\r\n8.6\sis\snot\saffected:\sthere\s`clock\sformat`\sis\sTcl\scode\s(`FormatNumericTimeZone`)\sand\sprints\s`+1004039`\swithout\strouble.\sThe\sC\sformat\sengine\sand\sthis\sreservation\scame\sto\sthe\srelease\sline\swith\sthe\sclock\srewrite\sin\s9.0\s(TIP\s688),\sfrom\sthe\sclock\sspeed-up\sbranch\sof\s2017\sand\s2018.\r\n\r\n**Fix\ssuggestion.**\r\n\r\n-\sIn\s`ClockFmtToken_TimeZone_Proc`,\sreserve\sroom\sfor\sthe\slongest\spossible\soutput:\ssign,\sup\sto\s6\sdigits\sof\shours\sfor\sa\s32-bit\soffset,\s2\sof\sminutes\sand\s2\sof\sseconds,\sthat\sis\s`FrmResultAllocate(dateFmt,\s11)`.\sAlternatively\scompute\sthe\swidth\sof\sthe\shours\sfirst\sand\sreserve\sexactly\swhat\sis\sneeded.\r\n-\sNegate\sthe\soffset\swithout\ssigned\soverflow,\sfor\sexample\sin\san\sunsigned\sor\s64-bit\svariable.\r\n-\sIndependently,\sin\s`clock.tcl`,\sreject\sfixed\soffsets\sand\sPOSIX\soffsets\swith\sminutes\sor\sseconds\sof\s60\sor\smore\s(and\spossibly\shours\sabove\s24),\sso\sthat\s`+99:99:99`\sbecomes\sa\s"time\szone\snot\sfound"\serror\sinstead\sof\sa\s100-hour\soffset.\sThis\schanges\sbehaviour\sthat\s8.6\sshares,\sso\sit\smay\sbe\sa\sseparate\sdecision;\sthe\sC\schange\salone\sfixes\sthe\soverflow.\r\n\r\nThe\sattached\spatch\sagainst\strunk\sdoes\sthe\sfirst\stwo:\sit\smakes\sthe\soffset\sa\s`Tcl_WideInt`\sbefore\snegating\sit\sand\sreserves\s11\scharacters.\sIt\sadds\stests\sclock-72.1\sto\sclock-72.4\s(items\s1\sand\s2,\sstack\sand\sheap\sbuffer,\slargest\sand\ssmallest\soffset).\sWithout\sthe\sfix,\sthey\smake\sASan\sand\sUBSan\sreport\sthe\soverflows\sand\sthe\snegation;\swith\sit,\sthey\spass,\sand\s`clock.test`\spasses\sin\sfull.\sThe\sC\spart\sapplies\sunchanged\sto\s9.1.0\sand\s9.0.4.\sThe\s`clock.tcl`\scheck\sis\snot\sin\sthe\spatch.
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 Severe
J status Open
J submitter bef
J subsystem 16.\sCommands\sA-H
J title Stack\sand\sheap\sbuffer\soverflow\sin\s`clock\sformat\s%z`
J type Bug
K e713c36677dda525f53876e152024daac73fae24
U bef
Z ca5ba1ab81aacc8c140f95b97f0495f1