.
D 2022-10-02T14:04:32.930
J assignee nobody
J closer nobody
J cmimetype text/x-fossil-wiki
J comment Although\sit\sonly\smakes\ssense\sto\sprovide\snonnegative\s<tt>argc</tt>\sto\s\s<tt>Tcl_Merge()</tt>,\sthe\sfunction\sis\sa\spublic\sAPI\scurrently\smaking\sno\seffort\sto\sguard\sagainst\snegative\s<tt>argc</tt>.\r\n\r\n<ul><li>When\s<tt>argc</tt>\sis\snegative,\sthere\sis\ssigned\sinteger\soverflow\sin\sthe\sexpression\s<tt>INT_MAX\s-\sargc\s+\s1</tt>.</li>\r\n\r\n<li>(Assuming\s32-bit\s<tt>int</tt>.)\sIf\s<tt>argc\s==\sINT_MIN</tt>,\sthe\scurrent\sbehavior\sis\sto\sallocate\sa\s2GiB\sbuffer\sand\sthen\swrite\s<tt>'\\0'</tt>\sto\sthe\sbyte\sprior\sto\sthe\sbeginning\sof\sbuffer.\sOtherwise,\sif\s<tt>INT_MIN\s<\sargc\s&&\sargc\s<\s0</tt>,\sthen\sthe\sfunction\spanics,\sclaiming\s<tt>max\ssize\sfor\sa\sTcl\svalue\s(2147483647\sbytes)\sexceeded</tt>.</li></ul>\r\n\r\nAt\sa\sminimum,\sI\swould\ssuggest\schanging\sthe\sbehavior\sof\sthe\sfunction\sslightly\sso\sthat\sit\salways\spanics\sto\sprevent\sthe\sout-of-bounds\swrite;\spanicking\sis\salready\spossible\sin\sthat\scase\sduring\sthe\s<tt>ckalloc(INT_MIN)</tt>\scall.\sMaybe\sa\smore\shelpful\spanic\smessage\scan\sbe\sused.\sSee\sattached\spatch\sfor\sa\spossible\ssolution.
J foundin core-8-6-branch
J is_private 0
J login chrstphrchvz
J priority 5\sMedium
J resolution None
J severity Minor
J status Open
J submitter chrstphrchvz
J subsystem 14.\sList\sObject
J title Tcl_Merge():\sout-of-bounds\swrite,\smore\ssigned\sinteger\soverflow
J type Patch
K 1599352cca83527b22000b9e6a336fa84344bf61
U chrstphrchvz
Z f6ad9c7eb97d6ad3e3ed82050eefddb3