<i>Use-after-free in Tcl_DStringAppend</i> status still Pending with 4 other changes
by
.
D 2016-06-21T00:53:43.568
J icomment Danger,\sWill\sRobinson\r\nThere's\ssome\swicked\saction\sgoing\son\sin\sTk.\r\nIn\sgeneric/tkwindow.c\sin\sfunction\sInitialize\sapprox\sline\s3193\r\nWe\shit\sthis\scode\spath:\r\n\r\n\s\s\s\s/*\r\n\s\s\s\s\s*\sFigure\sout\sthe\sapplication's\sname\sand\sclass.\r\n\s\s\s\s\s*/\r\n\r\n\s\s\s\sTcl_DStringInit(&class);\r\n\s\s\s\sif\s(name\s==\sNULL)\s{\r\n\s\s\s\s\s\s\s\sint\soffset;\r\n\s\s\s\s\s\s\s\sTkpGetAppName(interp,\s&class);\r\n\s\s\s\s\s\s\s\soffset\s=\sTcl_DStringLength(&class)+1;\r\n\s\s\s\s\s\s\s\sTcl_DStringSetLength(&class,\soffset);\r\n\s\s\s\s\s\s\s\sTcl_DStringAppend(&class,\sTcl_DStringValue(&class),\soffset-1);\r\n\s\s\s\s\s\s\s\sname\s=\sTcl_DStringValue(&class)\s+\soffset;\r\n\s\s\s\s}\r\n\r\nWhat's\sthe\sproblem\shere?\r\nIf\swe're\sworking\swith\sa\sstring\slonger\sthan\swill\sfit\sin\sDString's\sstatic\sstorage\sthen\sDStringAppend\scan\sckrealloc\shere,\sbut\swe're\spassing\sa\spointer\sto\sthe\svery\smemory\swe're\sreallocating!\s\r\n\r\nThis\scode\sdoesn't\smake\ssense\sto\sme\seither,\swhy\sis\sit\staking\sa\sname\s'foo'\sand\sappending\sit\sonto\sitself?\r\n\r\nI\sthink\sit\scan\sbe\sreduced\sto\ssimply\sthis:\r\nif\s(name\s==\sNULL)\s{\r\n\s\s\s\sTkpGetAppName(interp,\s&class);\r\n\s\s\s\sname\s=\sTcl_DStringValue(&class);\r\n}\r\n\r\nI\scan\sprovide\sa\sdemo\sif\snecessary\sbut\sI\sbelieve\sthis\sevil\sline:\r\nTcl_DStringAppend(&class,\sTcl_DStringValue(&class),\soffset-1);\r\nspeaks\sfor\sitself\sand\sindeed\sis\sthe\sculprit\shere.\r\n\r\nFinally\sand\sa\sbit\sunrelated,\sthere\sare\slimits\sto\sWindow\sclass\snames,\sOn\sMicrosoft\sWindows\sthe\smax\sis\s256\s(OS\slimitation).\sSo\sif\syou\sget\scrazy\swith\slong\snames,\sTk\swill\ssilently\snot\sdisplay\sany\swindow.
J login dah
J mimetype text/plain
J username dah
K d59715d0cffb0b86427b164188c95f2a06d88c17
U dah
Z cb179fc0b0cff58f6e350dfa60018899