.
D 2021-12-22T18:45:50.966
J assignee nobody
J closer nobody
J cmimetype text/x-fossil-wiki
J comment Example:\r\n\r\n<blockquote><pre>\r\nproc\smyproc\s{s}\s{\r\n\s\s\s\sputs\s[string\smap\s{abc\sdef}\s$s]\r\n}\r\n\r\nmyproc\s{zzzzzza}\r\n</pre></blockquote>\r\n\r\nAddressSanitizer\s(<tt>-fsanitize=address</tt>,\sused\swith\s<tt>-DPURIFY</tt>,\sLinux\sx86)\serror:\r\n\r\n<blockquote><pre>\r\n=================================================================\r\n<span\sstyle="font-weight:bold;color:red">==16557==ERROR:\sAddressSanitizer:\sheap-buffer-overflow\son\saddress\s0xb143d0e0\sat\spc\s0xb7a8d726\sbp\s0xbfbf2438\ssp\s0xbfbf2008</span>\r\n<span\sstyle="font-weight:bold;color:blue">READ\sof\ssize\s6\sat\s0xb143d0e0\sthread\sT0</span>\r\n\s\s\s\s#0\s0xb7a8d725\sin\sMemcmpInterceptorCommon(void*,\sint\s(*)(void\sconst*,\svoid\sconst*,\sunsigned\slong),\svoid\sconst*,\svoid\sconst*,\sunsigned\slong)\s/build/gcc/src/gcc/libsanitizer/sanitizer_common/sanitizer_common_interceptors.inc:860\r\n\s\s\s\s#1\s0xb7a8dd48\sin\s__interceptor_memcmp\s/build/gcc/src/gcc/libsanitizer/sanitizer_common/sanitizer_common_interceptors.inc:892\r\n\s\s\s\s#2\s0xb7a8dd48\sin\s__interceptor_memcmp\s/build/gcc/src/gcc/libsanitizer/sanitizer_common/sanitizer_common_interceptors.inc:887\r\n\s\s\s\s#3\s0xb63ddad3\sin\sTEBCresume\stcl/generic/tclExecute.c:5859\r\n\s\s\s\s#4\s0xb5d74c43\sin\sTclNRRunCallbacks\stcl/generic/tclBasic.c:4503\r\n\s\s\s\s#5\s0xb5d719e4\sin\sTcl_EvalObjv\stcl/generic/tclBasic.c:4226\r\n\s\s\s\s#6\s0xb5d80013\sin\sTclEvalEx\stcl/generic/tclBasic.c:5372\r\n\s\s\s\s#7\s0xb653cafa\sin\sTcl_FSEvalFileEx\stcl/generic/tclIOUtil.c:1824\r\n\s\s\s\s#8\s0xb6577599\sin\sTcl_MainEx\stcl/generic/tclMain.c:403\r\n\s\s\s\s#9\s0x447253\sin\smain\stcl/unix/tclAppInit.c:84\r\n\s\s\s\s#10\s0xb4f7998c\sin\s__libc_start_main\s(/usr/lib/libc.so.6+0x1e98c)\r\n\s\s\s\s#11\s0x447114\sin\s_start\s(tclsh8.6+0x1114)\r\n\r\n<span\sstyle="font-weight:bold;color:green">0xb143d0e0\sis\slocated\s0\sbytes\sto\sthe\sright\sof\s32-byte\sregion\s[0xb143d0c0,0xb143d0e0)</span>\r\n<span\sstyle="font-weight:bold;color:magenta">allocated\sby\sthread\sT0\shere:</span>\r\n\s\s\s\s#0\s0xb7aaf99d\sin\s__interceptor_realloc\s/build/gcc/src/gcc/libsanitizer/asan/asan_malloc_linux.cpp:164\r\n\s\s\s\s#1\s0xb5d2b7de\sin\sTclpRealloc\stcl/generic/tclAlloc.c:747\r\n\s\s\s\s#2\s0xb5dc036a\sin\sTcl_Realloc\stcl/generic/tclCkalloc.c:1147\r\n\s\s\s\s#3\s0xb665b526\sin\sGrowUnicodeBuffer\stcl/generic/tclStringObj.c:227\r\n\s\s\s\s#4\s0xb6671b61\sin\sExtendUnicodeRepWithString\stcl/generic/tclStringObj.c:3083\r\n\s\s\s\s#5\s0xb6671602\sin\sFillUnicodeRep\stcl/generic/tclStringObj.c:3058\r\n\s\s\s\s#6\s0xb665dcb5\sin\sTcl_GetUnicodeFromObj\stcl/generic/tclStringObj.c:725\r\n\s\s\s\s#7\s0xb63dd3aa\sin\sTEBCresume\stcl/generic/tclExecute.c:5835\r\n\s\s\s\s#8\s0xb5d74c43\sin\sTclNRRunCallbacks\stcl/generic/tclBasic.c:4503\r\n\s\s\s\s#9\s0xb5d719e4\sin\sTcl_EvalObjv\stcl/generic/tclBasic.c:4226\r\n\s\s\s\s#10\s0xb5d80013\sin\sTclEvalEx\stcl/generic/tclBasic.c:5372\r\n\s\s\s\s#11\s0xb653cafa\sin\sTcl_FSEvalFileEx\stcl/generic/tclIOUtil.c:1824\r\n\s\s\s\s#12\s0xb6577599\sin\sTcl_MainEx\stcl/generic/tclMain.c:403\r\n\s\s\s\s#13\s0x447253\sin\smain\stcl/unix/tclAppInit.c:84\r\n\s\s\s\s#14\s0xb4f7998c\sin\s__libc_start_main\s(/usr/lib/libc.so.6+0x1e98c)\r\n\r\nSUMMARY:\sAddressSanitizer:\sheap-buffer-overflow\s/build/gcc/src/gcc/libsanitizer/sanitizer_common/sanitizer_common_interceptors.inc:860\sin\sMemcmpInterceptorCommon(void*,\sint\s(*)(void\sconst*,\svoid\sconst*,\sunsigned\slong),\svoid\sconst*,\svoid\sconst*,\sunsigned\slong)\r\nShadow\sbytes\saround\sthe\sbuggy\saddress:\r\n\s\s0x362879c0:\s<span\sstyle="font-weight:bold;color:magenta">fd</span>\s<span\sstyle="font-weight:bold;color:red">fa</span>\s<span\sstyle="font-weight:bold;color:red">fa</span>\s<span\sstyle="font-weight:bold;color:red">fa</span>\s<span\sstyle="font-weight:bold;color:magenta">fd</span>\s<span\sstyle="font-weight:bold;color:magenta">fd</span>\s<span\sstyle="font-weight:bold;color:magenta">fd</span>\s<span\sstyle="font-weight:bold;color:red">fa</span>\s<span\sstyle="font-weight:bold;color:red">fa</span>\s<span\sstyle="font-weight:bold;color:red">fa</span>\s<span\sstyle="font-weight:bold;color:magenta">fd</span>\s<span\sstyle="font-weight:bold;color:magenta">fd</span>\s<span\sstyle="font-weight:bold;color:magenta">fd</span>\s<span\sstyle="font-weight:bold;color:red">fa</span>\s<span\sstyle="font-weight:bold;color:red">fa</span>\s<span\sstyle="font-weight:bold;color:red">fa</span>\r\n\s\s0x362879d0:\s<span\sstyle="font-weight:bold;color:magenta">fd</span>\s<span\sstyle="font-weight:bold;color:magenta">fd</span>\s<span\sstyle="font-weight:bold;color:magenta">fd</span>\s<span\sstyle="font-weight:bold;color:red">fa</span>\s<span\sstyle="font-weight:bold;color:red">fa</span>\s<span\sstyle="font-weight:bold;color:red">fa</span>\s<span\sstyle="font-weight:bold;color:magenta">fd</span>\s<span\sstyle="font-weight:bold;color:magenta">fd</span>\s<span\sstyle="font-weight:bold;color:magenta">fd</span>\s<span\sstyle="font-weight:bold;color:magenta">fd</span>\s<span\sstyle="font-weight:bold;color:red">fa</span>\s<span\sstyle="font-weight:bold;color:red">fa</span>\s00\s00\s00\s00\r\n\s\s0x362879e0:\s<span\sstyle="font-weight:bold;color:red">fa</span>\s<span\sstyle="font-weight:bold;color:red">fa</span>\s00\s00\s04\s<span\sstyle="font-weight:bold;color:red">fa</span>\s<span\sstyle="font-weight:bold;color:red">fa</span>\s<span\sstyle="font-weight:bold;color:red">fa</span>\s00\s00\s00\s<span\sstyle="font-weight:bold;color:red">fa</span>\s<span\sstyle="font-weight:bold;color:red">fa</span>\s<span\sstyle="font-weight:bold;color:red">fa</span>\s<span\sstyle="font-weight:bold;color:magenta">fd</span>\s<span\sstyle="font-weight:bold;color:magenta">fd</span>\r\n\s\s0x362879f0:\s<span\sstyle="font-weight:bold;color:magenta">fd</span>\s<span\sstyle="font-weight:bold;color:red">fa</span>\s<span\sstyle="font-weight:bold;color:red">fa</span>\s<span\sstyle="font-weight:bold;color:red">fa</span>\s<span\sstyle="font-weight:bold;color:magenta">fd</span>\s<span\sstyle="font-weight:bold;color:magenta">fd</span>\s<span\sstyle="font-weight:bold;color:magenta">fd</span>\s<span\sstyle="font-weight:bold;color:red">fa</span>\s<span\sstyle="font-weight:bold;color:red">fa</span>\s<span\sstyle="font-weight:bold;color:red">fa</span>\s<span\sstyle="font-weight:bold;color:magenta">fd</span>\s<span\sstyle="font-weight:bold;color:magenta">fd</span>\s<span\sstyle="font-weight:bold;color:magenta">fd</span>\s<span\sstyle="font-weight:bold;color:red">fa</span>\s<span\sstyle="font-weight:bold;color:red">fa</span>\s<span\sstyle="font-weight:bold;color:red">fa</span>\r\n\s\s0x36287a00:\s<span\sstyle="font-weight:bold;color:magenta">fd</span>\s<span\sstyle="font-weight:bold;color:magenta">fd</span>\s<span\sstyle="font-weight:bold;color:magenta">fd</span>\s<span\sstyle="font-weight:bold;color:red">fa</span>\s<span\sstyle="font-weight:bold;color:red">fa</span>\s<span\sstyle="font-weight:bold;color:red">fa</span>\s<span\sstyle="font-weight:bold;color:magenta">fd</span>\s<span\sstyle="font-weight:bold;color:magenta">fd</span>\s<span\sstyle="font-weight:bold;color:magenta">fd</span>\s<span\sstyle="font-weight:bold;color:red">fa</span>\s<span\sstyle="font-weight:bold;color:red">fa</span>\s<span\sstyle="font-weight:bold;color:red">fa</span>\s<span\sstyle="font-weight:bold;color:magenta">fd</span>\s<span\sstyle="font-weight:bold;color:magenta">fd</span>\s<span\sstyle="font-weight:bold;color:magenta">fd</span>\s<span\sstyle="font-weight:bold;color:red">fa</span>\r\n=>0x36287a10:\s<span\sstyle="font-weight:bold;color:red">fa</span>\s<span\sstyle="font-weight:bold;color:red">fa</span>\s<span\sstyle="font-weight:bold;color:magenta">fd</span>\s<span\sstyle="font-weight:bold;color:magenta">fd</span>\s<span\sstyle="font-weight:bold;color:magenta">fd</span>\s<span\sstyle="font-weight:bold;color:red">fa</span>\s<span\sstyle="font-weight:bold;color:red">fa</span>\s<span\sstyle="font-weight:bold;color:red">fa</span>\s00\s00\s00\s00[<span\sstyle="font-weight:bold;color:red">fa</span>]<span\sstyle="font-weight:bold;color:red">fa</span>\s<span\sstyle="font-weight:bold;color:magenta">fd</span>\s<span\sstyle="font-weight:bold;color:magenta">fd</span>\r\n\s\s0x36287a20:\s<span\sstyle="font-weight:bold;color:magenta">fd</span>\s<span\sstyle="font-weight:bold;color:red">fa</span>\s<span\sstyle="font-weight:bold;color:red">fa</span>\s<span\sstyle="font-weight:bold;color:red">fa</span>\s00\s00\s00\s<span\sstyle="font-weight:bold;color:red">fa</span>\s<span\sstyle="font-weight:bold;color:red">fa</span>\s<span\sstyle="font-weight:bold;color:red">fa</span>\s00\s00\s00\s<span\sstyle="font-weight:bold;color:red">fa</span>\s<span\sstyle="font-weight:bold;color:red">fa</span>\s<span\sstyle="font-weight:bold;color:red">fa</span>\r\n\s\s0x36287a30:\s00\s00\s00\s<span\sstyle="font-weight:bold;color:red">fa</span>\s<span\sstyle="font-weight:bold;color:red">fa</span>\s<span\sstyle="font-weight:bold;color:red">fa</span>\s00\s00\s04\s<span\sstyle="font-weight:bold;color:red">fa</span>\s<span\sstyle="font-weight:bold;color:red">fa</span>\s<span\sstyle="font-weight:bold;color:red">fa</span>\s00\s00\s04\s<span\sstyle="font-weight:bold;color:red">fa</span>\r\n\s\s0x36287a40:\s<span\sstyle="font-weight:bold;color:red">fa</span>\s<span\sstyle="font-weight:bold;color:red">fa</span>\s<span\sstyle="font-weight:bold;color:magenta">fd</span>\s<span\sstyle="font-weight:bold;color:magenta">fd</span>\s<span\sstyle="font-weight:bold;color:magenta">fd</span>\s<span\sstyle="font-weight:bold;color:red">fa</span>\s<span\sstyle="font-weight:bold;color:red">fa</span>\s<span\sstyle="font-weight:bold;color:red">fa</span>\s<span\sstyle="font-weight:bold;color:magenta">fd</span>\s<span\sstyle="font-weight:bold;color:magenta">fd</span>\s<span\sstyle="font-weight:bold;color:magenta">fd</span>\s<span\sstyle="font-weight:bold;color:red">fa</span>\s<span\sstyle="font-weight:bold;color:red">fa</span>\s<span\sstyle="font-weight:bold;color:red">fa</span>\s<span\sstyle="font-weight:bold;color:magenta">fd</span>\s<span\sstyle="font-weight:bold;color:magenta">fd</span>\r\n\s\s0x36287a50:\s<span\sstyle="font-weight:bold;color:magenta">fd</span>\s<span\sstyle="font-weight:bold;color:red">fa</span>\s<span\sstyle="font-weight:bold;color:red">fa</span>\s<span\sstyle="font-weight:bold;color:red">fa</span>\s<span\sstyle="font-weight:bold;color:magenta">fd</span>\s<span\sstyle="font-weight:bold;color:magenta">fd</span>\s<span\sstyle="font-weight:bold;color:magenta">fd</span>\s<span\sstyle="font-weight:bold;color:red">fa</span>\s<span\sstyle="font-weight:bold;color:red">fa</span>\s<span\sstyle="font-weight:bold;color:red">fa</span>\s<span\sstyle="font-weight:bold;color:magenta">fd</span>\s<span\sstyle="font-weight:bold;color:magenta">fd</span>\s<span\sstyle="font-weight:bold;color:magenta">fd</span>\s<span\sstyle="font-weight:bold;color:red">fa</span>\s<span\sstyle="font-weight:bold;color:red">fa</span>\s<span\sstyle="font-weight:bold;color:red">fa</span>\r\n\s\s0x36287a60:\s<span\sstyle="font-weight:bold;color:magenta">fd</span>\s<span\sstyle="font-weight:bold;color:magenta">fd</span>\s<span\sstyle="font-weight:bold;color:magenta">fd</span>\s<span\sstyle="font-weight:bold;color:red">fa</span>\s<span\sstyle="font-weight:bold;color:red">fa</span>\s<span\sstyle="font-weight:bold;color:red">fa</span>\s<span\sstyle="font-weight:bold;color:magenta">fd</span>\s<span\sstyle="font-weight:bold;color:magenta">fd</span>\s<span\sstyle="font-weight:bold;color:magenta">fd</span>\s<span\sstyle="font-weight:bold;color:red">fa</span>\s<span\sstyle="font-weight:bold;color:red">fa</span>\s<span\sstyle="font-weight:bold;color:red">fa</span>\s<span\sstyle="font-weight:bold;color:magenta">fd</span>\s<span\sstyle="font-weight:bold;color:magenta">fd</span>\s<span\sstyle="font-weight:bold;color:magenta">fd</span>\s<span\sstyle="font-weight:bold;color:red">fa</span>\r\nShadow\sbyte\slegend\s(one\sshadow\sbyte\srepresents\s8\sapplication\sbytes):\r\n\s\sAddressable:\s\s\s\s\s\s\s\s\s\s\s00\r\n\s\sPartially\saddressable:\s01\s02\s03\s04\s05\s06\s07\s\r\n\s\sHeap\sleft\sredzone:\s\s\s\s\s\s\s<span\sstyle="font-weight:bold;color:red">fa</span>\r\n\s\sFreed\sheap\sregion:\s\s\s\s\s\s\s<span\sstyle="font-weight:bold;color:magenta">fd</span>\r\n[…]\r\n==16557==ABORTING\r\n</pre></blockquote>\r\n\r\nThis\sis\scaused\sby\s<tt>memcmp()</tt>\sbeing\scalled\seven\swhen\sthe\sremaining\sportion\sof\sthe\soperand\sstring\sis\sshorter\sthan\sthe\smatch\sstring,\spresent\ssince\s[b6871e5b803d].\sUnlike\ssome\sother\sstring\scomparison\sfunctions,\s<tt>memcmp()</tt>\srequires\sbuffers\sto\sbe\svalid\sfor\sthe\slength\sspecified\seven\sif\sthey\sdiffer\swithin\sthe\svalid\srange\sof\sthe\sshorter\sbuffer\s(I\sam\saware\ssome\sfind\sthis\srestriction\scontroversial).\sI\sbelieve\sthe\sfix\sis\sto\scheck\swhether\sthe\sremainder\sof\sthe\sstring\sis\sat\sleast\sas\slong\sas\sthe\smatch\sstring,\scomparable\sto\swhat\sis\sdone\sin\s<tt>StringMapCmd()</tt>\s(generic/tclCmdMZ.c)\ssince\s[fab27ad2b82f]\sbecause\s<tt>Tcl_UniCharNcmp()</tt>\sand\s<tt>Tcl_UniCharNcasecmp()</tt>\slikewise\sassume\sboth\sstrings\sare\sat\sleast\sthe\sspecified\snumber\sof\scharacters\slong.\r\n\r\n<pre>\r\ndiff\s--git\sgeneric/tclExecute.c\sgeneric/tclExecute.c\r\nindex\s7e014d4..accdbe7\s100644\r\n---\sgeneric/tclExecute.c\r\n+++\sgeneric/tclExecute.c\r\n@@\s-5855,7\s+5855,9\s@@\sTEBCresume(\r\n\s\tp\s=\sustring1;\r\n\s\tend\s=\sustring1\s+\slength;\r\n\s\tfor\s(;\sustring1\s<\send;\sustring1++)\s{\r\n<span\sstyle="color:red">-\t\s\s\s\sif\s((*ustring1\s==\s*ustring2)\s&&\s(length2==1\s||</span>\r\n<span\sstyle="color:green">+\t\s\s\s\sif\s((*ustring1\s==\s*ustring2)\s&&\r\n+\t\t/*\sFix\sbug\shhhhhhhhhh:\srestrict\smax\scompare\slength.\s*/\r\n+\t\t(end-ustring1\s>=\slength2)\s&&\s(length2==1\s||</span>\r\n\s\t\t\s\s\s\smemcmp(ustring1,\sustring2,\ssizeof(Tcl_UniChar)\s*\slength2)\r\n\s\t\t\t\s\s\s\s==\s0))\s{\r\n\s\t\tif\s(p\s!=\sustring1)\s{\r\n</pre>
J foundin 8.6.12
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 18.\sCommands\sM-Z
J title TEBCResume():\sbuffer\sover-read\sin\sINST_STR_MAP
J type Patch
K 69218ab7bf0014c813964631b955509e4d16ae44
U chrstphrchvz
Z c7e0965a708f61b676e00a82a073a595