<i>Several trim mechanisms cause segfault / wrong check for NTS</i> status still Open with 3 other changes
by
.
D 2018-03-13T19:03:08.021
J comment I\snoticed\ssegfaults\sin\scase\sof\sTclTrim\s(left/right)\sfor\snon-NTS\sstring\srepresentation\s(I\sknow,\sthis\sis\salmost\sunexpected,\sbut\smay\shappen\susing\ssome\smodules).\r\n\r\nVery\sstrange\sis\sthat\sit\smay\scause\ssegfault\seven\sby\svalidity\scheck\sof\sthe\sNTS-string\s(to\savoid\ssegfault)!\swhich\sis\sIMHO\sdo\snot\sproper\simplemented:\r\nEven\sto\sprotect\sa\snon-usage\sof\ssuch\snon-NTS\sstring,\sTcl\schecks\scurrently\susing\saccess\sof\sbyte,\sthat\smay\sbe\sout\sof\srange\s(so\scauses\saccess\sviolation\sinstead\sof\spanic):\r\n<code><pre>\r\n\s\s\s\sif\s((bytes[numBytes]\s!=\s'\\0')\s||\s(trim[numTrim]\s!=\s'\\0'))\s{\r\n\tTcl_Panic("TclTrimRight\sworks\sonly\son\snull-terminated\sstrings");\r\n\s\s\s\s}\r\n</pre></code>\r\n\r\nI\srepeat\sagain,\sI\sknow\sthat\snon-NTS\sis\snot\s"good"\sat\sall,\sbut\sif\snevertheless\soccurred,\sthis\sone\s-\s`bytes[numBytes]`\sis\sunexpected\sas\sproper\svalidity\scheck\sfor\sNTS\s(even\sbecause\sinstead\sof\spanic\syou\scan\sget\ssegfault).\r\n\r\nThus\srewritten\snow\susing\smore\ssafe\svariant\s(implemented\swithout\spanic,\susing\snew\sfunction\sTclUtfWellFormedEnd,\sthat\scan\sdo\sthe\ssame\scheck,\sbut\swithout\saccess\sof\sbytes\soutside\sof\sbounds).\r\n\r\n\r\nA\sbranch\s[sebres-8-5-fix-trim-on-mailformed]\sfixes\sthis.\r\n\r\nThis\schecks\sthe\send-character\sis\swell-formed\sutf8-sequence\snow\s(and\sif\snot,\sdoes\sin-place\scall\sof\strim\son\sproper\sstring\srepresentation,\swhich\scontains\sa\sNTS\szero-byte\sat\send).\r\n\r\nAdditionally:\r\n\r\n\s\s-\sboth\swork\swell\snow\son\snon-NTS\sstrings\s(without\snull\scharacter\sat\send)\swithout\spanic;\r\n\r\n\s\s-\sfixed\swrong\soffsets\s(trim-length\sif\slast\schar\swas\smalformed\sin\scase\sof\sout\sof\srange),\sfor\sexample\sif\sthis\scharacter\s(like\s`\\xC0\\x00`\swill\srecognized\sas\s2\sbytes\schar\sand\strimmed\swith\stoo\slong\soffset,\sresults\spreviously\sin\snegative\slength);\r\n\r\n\s\s-\snew\sfunction\sTclTrim\sintroduced\s(as\ssafe\scombination\sof\sTclTrimLeft/TclTrimRight).\r\n\r\nPlease\sreview\sand\smerge\sin\s8.6\sand\strunk.
J login sebres
J mimetype text/plain
K de243b694daaf06e6a0fbcbeb7279c326c25551c
U sebres
Z 7a457009e425538e67a5deb28e205f82