Skip to content
Tcl Source Code History Of Ticket efd15d181ae9be3b
Login

History Of Ticket efd15d181ae9be3b

Artifacts Associated With Ticket efd15d181ae9be3b

  1. Ticket change [ab44091769] (rid 185245) by anonymous on 2020-07-25 14:37:56:

    1. assignee initialized to: "nobody"
    2. closer initialized to: "nobody"
    3. cmimetype initialized to: "text/plain"
    4. 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.
      
    5. foundin initialized to: "8.6.10.1"
    6. is_private initialized to: "0"
    7. login: "anonymous"
    8. priority initialized to: "5 Medium"
    9. resolution initialized to: "None"
    10. severity initialized to: "Important"
    11. status initialized to: "Open"
    12. submitter initialized to: "anonymous"
    13. subsystem initialized to: "16. Commands A-H"
    14. title initialized to: "problem with % in [exec] on windows"
    15. type initialized to: "Bug"
  2. Ticket change [4eb08d3a82] (rid 185270) by jan.nijtmans on 2020-07-26 17:13:17:

    1. assignee changed to: "sebres"
    2. 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?
      
    3. login: "jan.nijtmans"
    4. mimetype: "text/x-fossil-wiki"
    5. resolution changed to: "Works For Me"
    6. status changed to: "Pending"
  3. Ticket change [9bc0bbb0da] (rid 185271) by anonymous on 2020-07-27 08:25:14:

    1. 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 .
      
    2. login: "anonymous"
    3. mimetype: "text/plain"
  4. Ticket change [9168b08841] (rid 185274) by bll on 2020-07-28 01:52:51:

    1. 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).
      
    2. login: "bll"
    3. mimetype: "text/plain"
  5. Ticket change [7747bd6406] (rid 185275) by anonymous on 2020-07-28 07:28:55:

    1. 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.
      
    2. login: "anonymous"
    3. mimetype: "text/plain"
  6. Ticket change [aafc0b24cd] (rid 185276) by bll on 2020-07-29 14:38:35:

    1. 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.
      
    2. login: "bll"
    3. mimetype: "text/plain"
  7. Ticket change [62f8d64656] (rid 185277) by bll on 2020-07-29 14:40:02:

    1. 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.
      
    2. login: "bll"
    3. mimetype: "text/plain"
  8. Ticket change [f4d341a143] (rid 185278) by bll on 2020-07-29 14:51:54:

    1. 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.
      
    2. login: "bll"
    3. mimetype: "text/plain"
    4. resolution changed to: "None"
    5. status changed to: "Open"
  9. Ticket change [0cd4bc9531] (rid 185299) by sebres on 2020-08-04 16:09:02:

    1. closedate changed to: "2459066.17294007"
    2. closer changed to: "sebres"
    3. 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].
      
    4. login: "sebres"
    5. mimetype: "text/x-fossil-wiki"
    6. resolution changed to: "Duplicate"
    7. status changed to: "Closed"