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

Artifact [8fd47123d5]

Artifact 8fd47123d554c1e3f3000f88f08ca1c194767af4dcc883bcd973dfeb71601a82:

Ticket change [8fd47123d5] - Ticket [e713c36677dda525|e713c36677] <i>Stack and heap buffer overflow in `clock format %z`</i> status still Open with 3 other changes by bef on 2026-11-05 21:24:13.
D 2026-11-05T21:24:13.005
J icomment A\ssecond\soverflow\sin\sthe\ssame\sresult\sbuffer,\swith\sthe\ssame\sreach\s(safe\schild\sthrough\sthe\s`clock`\salias,\sor\sa\strusted\s`clock\sformat`\swith\sa\stime\szone\sfrom\soutside\sdata;\sthe\sdefault\sformat\scontains\s`%Z`,\sso\sno\s`-format`\sis\sneeded).\sTrunk,\s9.1.0\sand\s9.0.4\sare\saffected;\s8.6\sis\snot.\r\n\r\n`FrmResultAllocate(DateFormat\s*,\sint\slen)`\s(`tclClockFmt.c:2714`)\sis\scalled\swith\s`Tcl_Size`\slengths,\sand\scomputes\s`needed`\sand\s`newsize`\sas\s`int`.\sFor\sa\s`%Z`\szone\sname\sor\sa\sliteral\sformat\sword\sof\s2\sGiB\sor\smore,\s`needed`\scomes\sout\snegative,\snothing\sis\sreserved,\sand\sthe\sfollowing\s`memcpy`\s(`:2958`\sfor\s`%Z`,\s`:3517`\sfor\sa\sword)\scopies\sthe\sfull\slength\sinto\sthe\s80-byte\s`resMem`\son\sthe\sstack.\sAbove\s4\sGiB\sthe\slength\swraps\sto\sa\ssmall\spositive\svalue\sand\sthe\scopy\soverruns\sa\ssmall\sheap\sblock\sinstead.\sThe\sfixed-offset\spattern\sin\s`clock.tcl`\sis\snot\sanchored\sat\sthe\send,\sso\s`+00`\sfollowed\sby\sanything\sis\saccepted,\sand\sthe\swhole\sstring\sbecomes\sthe\szone\sname.\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-format\s%Z\s-timezone\s[string\srepeat\s+00\s715827916]\r\n\s\s\s\s}\r\n\r\n\s\s\s\sWRITE\sof\ssize\s2147483749\s...\r\n\s\s\s\s#1\sClockFmtToken_TimeZone_Proc\stclClockFmt.c:2958\r\n\s\s\s\sSUMMARY:\sAddressSanitizer:\sstack-buffer-overflow\stclClockFmt.c:2958\sin\sClockFmtToken_TimeZone_Proc\r\n\r\n`clock\sformat\s0\s-gmt\s1\s-format\s[string\srepeat\sx\s2147483748]`\sgives\sthe\ssame\sat\s`:3517`.\sWithout\ssanitisers\sthe\sprocess\sdies\swith\sSIGSEGV\sor\sSIGBUS.\sThe\s`%Z`\scase\sneeds\sabout\s10\sGiB\sof\smemory,\sbecause\sof\sthe\sUCS-4\scopy\sof\sthe\szone\smade\sby\sthe\sregexp\sin\s`SetupTimeZone`;\sthe\sword\scase\sneeds\sabout\s4\sGiB.\r\n\r\nSuggested\sfix,\son\stop\sof\sthe\spatch\sattached\sto\sthis\sticket\s(it\stouches\sdifferent\slines):\r\n\r\n```diff\r\n\sstatic\sinline\sint\r\n\sFrmResultAllocate(\r\n\s\s\s\s\sDateFormat\s*dateFmt,\r\n-\s\s\s\sint\slen)\r\n+\s\s\s\sTcl_Size\slen)\r\n\s{\r\n-\s\s\s\sint\sneeded\s=\sdateFmt->output\s+\slen\s-\sdateFmt->resEnd;\r\n+\s\s\s\sTcl_Size\sneeded\s=\sdateFmt->output\s+\slen\s-\sdateFmt->resEnd;\r\n\s\s\s\s\sif\s(needed\s>=\s0)\s{\t\t/*\s>=\s0\s-\sregards\sNTS\szero\s*/\r\n-\tint\snewsize\s=\sdateFmt->resEnd\s-\sdateFmt->resMem\r\n+\tTcl_Size\snewsize\s=\sdateFmt->resEnd\s-\sdateFmt->resMem\r\n\s\t\t+\sneeded\s+\sMIN_FMT_RESULT_BLOCK_ALLOC\s*\s2;\r\n```\r\n\r\nWhen\sthe\sallocation\sfails,\sthe\sfunction\sreturns\s`TCL_ERROR`\swithout\ssetting\sa\smessage,\sso\s`clock\sformat`\sfails\swith\san\sempty\serror.\sSeparately,\sanchoring\sthe\sfixed-offset\spattern\sin\s`clock.tcl`\swith\s`$`\swould\sstop\sarbitrary\stext\sfrom\sbecoming\sa\szone\sname.\sThat\schanges\saccepted\sinput,\sthough,\sand\s8.6\sshares\sit.
J login bef
J mimetype text/x-markdown
K e713c36677dda525f53876e152024daac73fae24
U bef
Z ddf1574d335386f3b428277ebff677bc