Artifacts Associated With Ticket efd15d181ae9be3b
Ticket change [ab44091769] (rid 185245) by anonymous on 2020-07-25 14:37:56:
- assignee initialized to: "nobody"
- closer initialized to: "nobody"
- cmimetype initialized to: "text/plain"
- comment initialized to:
Using percentage sign % in [exec] command or in [open] a command pipeline on windows is broken in recent version. Tcl version: 8.6.4.1 Tcl command: exec cmd /c echo %programdata% Command result: C:\ProgramData -> Result is correct Tcl version: 8.6.10.1 Tcl command: exec cmd /c echo %programdata% Command result: ""%"programdata"%"" -> Result is wrong I could not find a way how to pass-through a simple percentage sign unmasked to the underlaying windows operating system.
- foundin initialized to: "8.6.10.1"
- is_private initialized to: "0"
- login: "anonymous"
- priority initialized to: "5 Medium"
- resolution initialized to: "None"
- severity initialized to: "Important"
- status initialized to: "Open"
- submitter initialized to: "anonymous"
- subsystem initialized to: "16. Commands A-H"
- title initialized to: "problem with % in [exec] on windows"
- type initialized to: "Bug"
Ticket change [4eb08d3a82] (rid 185270) by jan.nijtmans on 2020-07-26 17:13:17:
- assignee changed to: "sebres"
- icomment:
This changed starting with commit [86e0fd3ecf9a48af] for security reasons. You should be able to use: <pre> exec cmd /c echo $env(programdata) </pre> @sebres, do you want to comment more on this change, why it was done?
- login: "jan.nijtmans"
- mimetype: "text/x-fossil-wiki"
- resolution changed to: "Works For Me"
- status changed to: "Pending"
Ticket change [9bc0bbb0da] (rid 185271) by anonymous on 2020-07-27 08:25:14:
- icomment:
What a really wanted to do: catch {exec WMIC PROCESS WHERE "NAME!='WMIC.EXE' AND \ COMMANDLINE LIKE '%MyJarFile.jar%-p 12345%'" \ GET PROCESSID /FORMAT:VALUE} result Percentage sign in Windows WMIC command stands for wildcard and not for Windows variable. Therefore using "env" does not help here. How is it possible to pass-through plain percentage sign? Maybe by masking it somehow? Seems no good decision to inhibit that totally . - login: "anonymous"
- mimetype: "text/plain"
- icomment:
Ticket change [9168b08841] (rid 185274) by bll on 2020-07-28 01:52:51:
- icomment:
Remember that Tcl will process the double quotes and in this instance you want to pass them to the WMIC command. For example, I have an exec in my program: set cmd "\"$::sysvars::v(prog.tasklist)\" /fi \"pid eq $ppid\" /nh 2>nul" exec -ignorestderr -- {*}$cmd 2>@1 as the quoted string: "pid eq <some-pid>" must be passed to windows with the double quotes included. Examples (these all work): % close [open "my file" w] % exec write "\"my file\"" % close [open abc%def w] % exec write abc%def % close [open %abcdef% w] % exec write %abcdef% % So try your command with the double quote marks escaped. This may take a little work to figure out. That's why I like to set the command line to execute first, then exec it with exec {*}$cmd. I can puts $cmd and see exactly what will be passed to exec (since it is a list, you have to remember that many words will be brace quoted). - login: "bll"
- mimetype: "text/plain"
- icomment:
Ticket change [7747bd6406] (rid 185275) by anonymous on 2020-07-28 07:28:55:
- icomment:
Not double quotation marks are making troubles but percentage signs! Tcl version: 8.6.4.1 Tcl command: exec wmic process where {commandline like '%wmic%'} get processid,commandline Command output: CommandLine ProcessId C:\WINDOWS\System32\Wbem\wmic.exe process where "commandline like '%wmic%'" get processid,commandline 2884 -> Result is correct Tcl version: 8.6.10.1 Tcl command: exec wmic process where {commandline like '%wmic%'} get processid,commandline Command output: No instances available -> Result is wrong Command does not contain any double quotation mark to be escaped or not! Either escaping percentage signs or single quotation marks results in wmic error message. So how should wmic command now look like in order to get correct result as before? Any working solution would be appreciated. - login: "anonymous"
- mimetype: "text/plain"
- icomment:
Ticket change [aafc0b24cd] (rid 185276) by bll on 2020-07-29 14:38:35:
- icomment:
Testing on windows (win7/64) where tt.exe dumps the command line arguments it bll@win7-64 MINGW64 ~ $ cat tt.tcl set out [exec ./tt wmic process where {commandline like '%wmic%'} get processid,commandline] puts $out exit bll@win7-64 MINGW64 ~ $ /c/Users/bll/Desktop/BallroomDJ/windows/64/tcl/bin/tclsh.exe tt.tcl argc: 7 0: C:\msys64\home\bll\tt.exe 1: wmic 2: process 3: where 4: commandline like '%wmic%' 5: get 6: processid,commandline Printing the constructed command line out in the Tcl source: ds: C:\msys64\home\bll\tt.exe wmic process where "commandline like '"%"wmic"%"'" get processid,commandline So something, somewhere is stripping out those quotation marks that get added by Tcl. I really don't know what is stripping the quotation marks. The program should receive them. Obviously cmd.exe /c echo %programdata% does receive the quotation marks and displays them (as it should). It looks broken to me. - login: "bll"
- mimetype: "text/plain"
- icomment:
Ticket change [62f8d64656] (rid 185277) by bll on 2020-07-29 14:40:02:
- icomment:
And the string in question is already quoted. It doesn't need to be protected, even if it was being passed to cmd.exe.
- login: "bll"
- mimetype: "text/plain"
- icomment:
Ticket change [f4d341a143] (rid 185278) by bll on 2020-07-29 14:51:54:
- icomment:
I suspect that mingw's argument processing on windows handles all the quotation marks for the user. That would explain my C program. I am reopening this ticket. On Windows, the program should receive the arguments as is, as on windows, the programs parse the arguments, not the shell.
- login: "bll"
- mimetype: "text/plain"
- resolution changed to: "None"
- status changed to: "Open"
- icomment:
Ticket change [0cd4bc9531] (rid 185299) by sebres on 2020-08-04 16:09:02:
- closedate changed to: "2459066.17294007"
- closer changed to: "sebres"
- icomment:
The main reason for the fix is described in [21b0629c81] (as well as self-descriptive in test cases). Shortly it is a certain insanity by the argument parsing in MS - in opposite to *nux the arguments are parsed by program so differently if called a program processor (comspec) and other executable. The current handling of %-char is not optimal (see further ticket [344b1a0c0f]) and I'll try to fix that, but this ticket is rather a duplicate, so I'll close it here. As for the fix, the main issue is that [https://github.com/sebres/PoC/issues/1|parameter substitution in comspec is ambiguous], so proper quoting/escape is hardly possible and [https://github.com/microsoft/terminal/issues/250|MS refuses to fix it due to compat reasons] Thus at the moment the fix may look like: <ul> <li>try to "escape" as safe as possible</li> <li>raise exception "Unpaired quote found" ...</li> </ul> Whereas it must additionally distinguish between execution of comspec (shell), a batch-script and other executable. Let alone the escape using <code>^</code> char together with double/triple quotation (or using <code>\"</code>) is impossible, the %-char is allowed as part of file name. Closed as dup of [344b1a0c0f]. - login: "sebres"
- mimetype: "text/x-fossil-wiki"
- resolution changed to: "Duplicate"
- status changed to: "Closed"