<i>exec and open | fail for .bat files if 8dot3name is disabled and path + command contain spaces</i>.
by
.
D 2013-07-22T14:01:12.132
J assignee nobody
J closer nobody
J cmimetype text/plain
J comment The\sissue\sis\sthat\squoting\sin\stclWinPipe.c\sdoes\snot\sproperly\shandle\scases\swhere\sa\sbat\sis\srun\sfrom\sGUI\s(which\sadds\scmd.exe\s/c\sto\srun\scommand)\sand\sarguments\sinclude\squotes\sas\swell.\r\n\r\nTo\sreproduce:\r\n\r\n-\sdisable\s8dot3name\s(fsutil\s8dot3name\sset\s1\sfrom\selevated\scommand\sprompt)\sand\sreboot\r\n\r\n-\screate\sa\sdir\swith\sspaces\s-\si.e.\sC:\\dir\swith\sspaces\r\n\r\n-\screate\sC:\\dir\swith\sspaces\\test.bat\r\n\r\n-\sexec\sC:/dir\swith\sspaces/test.bat\s""\r\n\r\nTcl\sfails\swith\serror:\r\n\r\n'C:/dir'\sis\snot\srecognized\sas\san\sinternal\sor\sexternal\scommand.\r\n\r\nThis\sis\sbecause\sinternally\sthe\sfollowing\scommand\sline\sis\sbuilt:\r\n\r\nC:\\Windows\\system32\\cmd.exe\s/c\s"C:\\dir\swith\sspaces\\test.bat"\s""\r\n\r\nIn\sthis\scase\s(where\smore\sthan\s2\squotes\sare\sused\sin\scmd\s/c\sinvocation),\scmd.exe\sstrips\sfirst\sand\slast\squotation\smark\sand\sin\sturn\stries\sto\srun:\r\n\r\nC:\\dir\swith\sspaces\\test.bat"\s"\r\n\r\nThe\sproper\ssolution\sis\sto\sadd\s/s\sswitch\s(which\swill\salways\scause\sfirst\sand\slast\squote\sto\sbe\sstripped,\sregardless\sof\snumber\sof\squotes)\sand\swrap\sthe\swhole\scommand\sline\sin\squotes:\r\n\r\nC:\\Windows\\system32\\cmd.exe\s/c\s""C:\\dir\swith\sspaces\\test.bat"\s"""\r\n\r\nWhich\swill\sin\sturn\srun:\r\n\r\n"C:\\dir\swith\sspaces\\test.bat"\s""\r\n\r\nMore\sinformation\sand\squote\sfrom\scmd.exe\s/?:\r\n\r\nhttp://stackoverflow.com/questions/355988/how-do-i-deal-with-quote-characters-when-using-cmd-exe\r\n\r\nSample\spatch\sto\sfix\sthe\sbehavior:\r\n\r\n---\stclWinPipe.c.orig\t2013-07-10\s12:56:21\s+0000\r\n+++\stclWinPipe.c\t2013-07-22\s13:51:14\s+0000\r\n@@\s-1126,7\s+1126,7\s@@\r\n\s\t\s\s\s\sstartInfo.wShowWindow\s=\sSW_HIDE;\r\n\s\t\s\s\s\sstartInfo.dwFlags\s|=\sSTARTF_USESHOWWINDOW;\r\n\s\t\s\s\s\screateFlags\s=\sCREATE_NEW_CONSOLE;\r\n-\t\s\s\s\sTcl_DStringAppend(&cmdLine,\s"cmd.exe\s/c",\s-1);\r\n+\t\s\s\s\sTcl_DStringAppend(&cmdLine,\s"cmd.exe\s/s\s/c",\s-1);\r\n\s\t}\selse\s{\r\n\s\t\s\s\s\screateFlags\s=\sDETACHED_PROCESS;\r\n\s\t}\r\n@@\s-1539,6\s+1539,7\s@@\r\n\s{\r\n\s\s\s\s\sconst\schar\s*arg,\s*start,\s*special;\r\n\s\s\s\s\sint\squote,\si;\r\n+\s\s\s\sint\sentireCommandQuote\s=\s0;\r\n\s\s\s\s\sTcl_DString\sds;\r\n\s\r\n\s\s\s\s\sTcl_DStringInit(&ds);\r\n@@\s-1549,7\s+1550,15\s@@\r\n\s\r\n\s\s\s\s\sTcl_DStringAppend(&ds,\sTcl_DStringValue(linePtr),\s-1);\r\n\s\s\s\s\sif\s(Tcl_DStringLength(linePtr)\s>\s0)\s{\r\n-\tTcl_DStringAppend(&ds,\s"\s",\s1);\r\n+\s\s\s\s\s\s\s\s//\sOn\sWindows\sNT,\scmd\s/c\s/s\srequires\squoting\sall\sparameters\r\n+\s\s\s\s\s\s\s\s//\swith\sa\squote\scharacter\sin\sorder\sto\spreserve\sinner\squotes\r\n+\s\s\s\s\s\s\s\s//\sof\sthe\scommand\sto\sbe\srun\r\n+\s\s\s\s\s\s\s\sif\s(TclWinGetPlatformId()\s==\sVER_PLATFORM_WIN32_NT)\s{\r\n+\t\s\s\s\sTcl_DStringAppend(&ds,\s"\s\\"",\s2);\r\n+\s\s\s\s\s\s\s\s\s\s\s\sentireCommandQuote\s=\s1;\r\n+\s\s\s\s\s\s\s\s}\s\selse\s\s{\r\n+\t\s\s\s\sTcl_DStringAppend(&ds,\s"\s",\s1);\r\n+\s\s\s\s\s\s\s\s}\r\n\s\s\s\s\s}\r\n\s\r\n\s\s\s\s\sfor\s(i\s=\s0;\si\s<\sargc;\si++)\s{\r\n@@\s-1617,6\s+1626,9\s@@\r\n\s\t\s\s\s\sTcl_DStringAppend(&ds,\s"\\"",\s1);\r\n\s\t}\r\n\s\s\s\s\s}\r\n+\s\s\s\sif\s(entireCommandQuote)\s{\r\n+\tTcl_DStringAppend(&ds,\s"\\"",\s1);\r\n+\s\s\s\s}\r\n\s\s\s\s\sTcl_DStringFree(linePtr);\r\n\s\s\s\s\sTcl_WinUtfToTChar(Tcl_DStringValue(&ds),\sTcl_DStringLength(&ds),\slinePtr);\r\n\s\s\s\s\sTcl_DStringFree(&ds);
J is_private 0
J login anonymous
J priority 5\sMedium
J private_contact 07a5c627b51b39b3731e24c890e2a2dd0ec40c59
J resolution None
J severity Critical
J status Open
J submitter anonymous
J subsystem 52.\sPortability\sSupport
J title exec\sand\sopen\s|\sfail\sfor\s.bat\sfiles\sif\s8dot3name\sis\sdisabled\sand\spath\s+\scommand\scontain\sspaces
J type Bug
K 6dacb3b6f0381d534f37ff419ab3b1a9028d04bc
U anonymous
Z ee5188f262549b32e1e9564918171d89