.
D 2010-11-26T01:19:45
J icomment The\sproblem\sis\sthat\s"internal"\scommands\sare\snot\sconsistent\swith\s"operating\ssystem"\scommands.\s\sEither\smake\sthe\sinternal\scommands,\slike\s[file\ssplit],\sstrip\sNULs\sand\ssubsequent\scharacters;\sor\smake\sthe\soperating\ssystem\scommands\streat\sfilenames\swith\sNULs\sas\snonexistent.\s\sI\sprefer\sthe\slatter\sapproach,\sbecause\sTcl\scan't\salways\sdistinguish\sbetween\sfilenames\sand\sother\sstrings:\sfilenames\sare\smanipulated\snot\sonly\sby\s[file]\sbut\salso\s[string]\sand\svariable\sinterpolation\sand\sother\smethods.\s\sAlso\sit\smight\sbe\sacceptable\sto\shave\sembedded\sNULs\sin\sthe\snames\sof\sfiles\son\sa\sVFS,\sjust\snot\sfor\sthe\snative\sfilesystem.\n\nYes,\sNULs\scome\sfrom\suser\sinput.\s\sI\sfound\sthis\swhile\stesting\sWibble:\shttp://wiki.tcl.tk/27378#pagetocdd31402f\s.\s\sThe\suser\scan\seasily\sinsert\sa\sNUL\sby\styping\s%00\sin\sthe\sURL;\sthis\sconvinces\sthe\s[string\smatch]\sthat\sthe\srequested\sfile\sdoesn't\smatch\sany\sof\sthe\sforbidden\spatterns,\sbut\sthen\s[open]\sdrops\sthe\sNUL\sand\s[chan\scopy]\shappily\ssends\sthe\sforbidden\sfile\sto\sthe\suser.\n\nI\scan't\seasily\sstrip\sNUL\sfrom\sfilenames\sin\sWibble\sbecause\sthe\score\scan't\stell\swhat\sparts\sof\sthe\sURI\sor\sPOST\swill\sultimately\scorrespond\sto\san\son-disk\sfile,\swhat\sparts\sare\snames\sof\sobjects\sthat\saren't\sdisk\sfiles\sand\scan\slegitimately\shave\sNULs,\sand\swhat\sparts\sare\sarbitrary\sbinary\sdata.\n\nWhat\scan\sI\sdo?\s\sHere's\sa\sscript\sto\sstrip\sNUL\sand\ssubsequent:\n\nproc\sstripnul\s{str}\s{\n\s\s\s\sif\s{[set\sindex\s[string\sfirst\s\\0\s$str]]\s==\s-1}\s{\n\s\s\s\s\s\s\s\sreturn\s$str\n\s\s\s\s}\selse\s{\n\s\s\s\s\s\s\s\sstring\srange\s$str\s0\s[expr\s{$index\s-\s1}]\n\s\s\s\s}\n}\n\nThen\sI\smust\suse\sthis\severy\stime\sI\smake\sany\sdecisions\son\sthe\sbasis\sof\sa\sfilename\sthat's\sassembled\sfrom\suser\sinput.\s\sThat's\sa\spain\sand\sthere's\sa\slot\sof\sroom\sfor\serror.\s\sOr,\sfix\sthe\sproblem\severywhere\sfor\severybody\sby\smaking\sthe\snative\sfilesystem\scode\streat\sfiles\swhose\snames\shave\sembedded\sNULs\sas\snonexistent.\s\sThat\smakes\ssense\sto\sme,\sbecause\sthere\s*aren't*\sany\sfiles\swith\sNULs\sin\stheir\snames!\n\nVery\sold\sversions\sof\sTcl\sused\sto\sstrip\sNUL\severywhere,\swhether\syou\sliked\sit\sor\snot.\s;^)\n
J login andygoth
J mimetype text/plain
J username andygoth
K 3118489fffffffffffffffffffffffffffffffff
U andygoth
Z 539c097cb344f553a51b4f192f520b66