Artifacts Associated With Ticket 344b1a0c0f
Ticket change [bc1d2ff4ea] (rid 168280) by mistachkin on 2019-01-15 17:54:58:
- assignee initialized to: "nobody"
- closer initialized to: "nobody"
- cmimetype initialized to: "text/plain"
- comment initialized to:
The following command apparently does not work correctly in Tcl 8.6.9: set res [exec -- $::env(ComSpec) /c echo %CD%] From "https://www.sqlite.org/src/artifact/aafcd5b0bc0f7?ln=177"
- foundin initialized to: "8.6.9"
- is_private initialized to: "0"
- login: "mistachkin"
- priority initialized to: "5 Medium"
- resolution initialized to: "None"
- severity initialized to: "Important"
- status initialized to: "Open"
- submitter initialized to: "mistachkin"
- subsystem initialized to: "16. Commands A-H"
- title initialized to: "exec on Windows broken when '%' is used"
- type initialized to: "Bug"
Ticket change [fb1ca4ff9a] (rid 168281) by sebres on 2019-01-15 18:43:49:
- icomment:
Confirmed. Basically, this is not a bug, but feature (I would say, I'm blame for this) to avoid windows vulnerable handling by (un)escape of the parameters, see [21b0629c81]. Just a bit incompatible feature in exactly this case. The substitution of system variables using percent-char was nowhere described resp. not documented in the exec-manual (still worse it is unclear in documentation of windows command processor too). Furthermore it could cause unexpected or even vulnerable behavior if calling batch-files, or executable from there. Possible solutions:<br/> - restore backwards-compatibility for call of the command-processor;<br/> - special option like --safe or --unsafe to use (or avoid) safe escaping at all;<br/> - rewrite the code in sqlite like: <pre style="padding-left:10pt"> <b style="color:red">- return [string map [list \\ /] \ - [string trim [exec -- $::env(ComSpec) /c echo %CD%]]]</b> <b style="color:green">+ return [file normalize [pwd]]</b> </pre> Or just remove this workaround completely, because pwd always return normalized path now, so this strange attempt to solve "case-mismatch issues on windows" is not expected anymore. I'm aware of the certain incompatibility here, and because the fix [21b0629c81] is anyway incomplete (see my last comment there), so I'm all ears for the suggestions or proposals how we could solve this.
- login: "sebres"
- mimetype: "text/x-fossil-wiki"
- icomment:
Ticket change [b34df665b6] (rid 168282) by mistachkin on 2019-01-15 19:16:02:
- icomment:
Sorry, but this is a clear regression from 8.6.8. Previously, this script, which is technically correct, worked fine. Now, it does not work. If this is an incompatible change done on purpose, it should have been saved for Tcl 9.0, or at least TIP'd. The workaround is in the test script for a reason.
- login: "mistachkin"
- mimetype: "text/plain"
- icomment:
Ticket change [448c228ab9] (rid 168283) by sebres on 2019-01-15 19:38:46:
- icomment:
<i>> Sorry, but this is a clear regression from 8.6.8.</i> And I'm aware of it. Just at the moment I'm not sure about the possible fix of the vulnerability without lost of the backwards-compatibility. So I'm basically with you - the regression has to be resolved now. Just searching for the proper solution. <i>> it should have been saved for Tcl 9.0, or at least TIP'd.</i> Normally sure, but not usually in case of the potential vulnerability (and unfortunately it is not just theoretical case).<br/> A programming language like Tcl (as many others) must fundamentally follow "Safety ahead of Compatibility" rule.
- login: "sebres"
- mimetype: "text/x-fossil-wiki"
- icomment:
Ticket change [e5efe114aa] (rid 168302) by sebres on 2019-01-17 09:00:11:
- icomment:
<p>Just for the record</p> <p>As for [pwd] normalization...<br>Well, as already said, I don't think it is still an issue under windows.</p> <p>As for "the percent character has to be escaped"... <br>Sure it must be, but for batch/exe, and as regards the execution of command processor - it was just unintended after-effect of the fix. Shit happens.<br>The escape is necessary because of certain issue how Windows processes unpaired quotes (it is vulnerable at the moment and MS won't fix this due to compat-reasons, see <a href="https://github.com/Microsoft/console/issues/250">Microsoft/console/issues/250)</a>, so it is possible to produce an unpaired quote after substitution of some env-vars (like paths, containing quotes, which are substituted in call, so no more under control of Tcl). Just because several quotation marks together are processed differently, there are even weird cases where triple-quotes will be unescaped similar to double-quotes, or they can even "reverse" unescape strategy MS used here. <br>For example <code>C" "C</code>, <code>"C C"</code> and <code>""C" "C""</code> are the same under windows, so following substitutions cause the same result:</p> <p><pre style="font-size: 80%"> > echo puts $::argv | tclsh - C" "C - {C C} > echo puts $::argv | tclsh - "C C" - {C C} > echo puts $::argv | tclsh - ""C" "C"" - {C C} </pre> So if you basically don't have the quotes under your control and in principle you do not, because the internal %-substitution of variables has precedence here, so could damn your composited command line, also in case it was initially quoted properly.<br>Then the usage of some parameters like "| %COMSPEC% /c do-something-evil" after such break, e. g. passed from foreign user-input and normally proper quoted/escaped as regards the single argument, allow intruder to construct an injection and produce exploit.<br><br>That's as regards the batch-execution etc.<br>As already said, cmd /c is rather an exception here (and was just an after-effect, so blame on me), but I'll try to provide the fix as soon as possible.</p> <p>As for "don't think that could be accomplished using double quotes". Yes you are right, it is not really possible, and this is also explained in <a href="https://core.tcl-lang.org/tcl/info/cc35e8ac4d9f98e6">my last comment</a> to mentioned 0-day vulni-ticket (but it is at least securer as it was previously).<br>The magic word here is circumflex (^) character and I've already potential solution for this, just the mixed escape using circumflex and quotes together is a bit complex (see <a href="https://github.com/sebres/PoC/issues/1">sebres/PoC/issues/1</a>). <br>Additionally it deviates a bit by the call of batch and executable, and I would resolve this deviation before, as well as provide good test-coverage for both variants (now 3, inclusive comspec).</p> <p>17.01.2019 01:19, Joe Mistachkin wrote:</p> <blockquote type="cite" style="padding-left: 5px; border-left: #1010ff 2px solid; margin-left: 5px"> <div dir="ltr"> <div>The original problem being solved was that [pwd] did not preserve the exact case of the current directory. I'm struggling to recall, but I think making the test result comparison case-insensitive was not an appropriate option.</div> <div> </div> <div>That being said, given the command escaping algorithm in use for Windows [exec] in 8.6.9, I'm surprised that other people haven't noticed that things don't work quite the same. Also, I'm confused by the percent character has to be escaped, since it does not typically impact argument boundaries on Windows. Furthermore, *if* it had to be escaped, I don't think that could be accomplished using double quotes.</div> - login: "sebres"
- mimetype: "text/html"
- icomment:
Ticket change [00444754bb] (rid 185300) by bll on 2020-08-04 17:30:24:
- icomment:
Is this trying to fix a vulnerability in Windows? Or Tcl? I don't think trying to fix Windows issues is a good use of time. cmd.exe is known to be broken, nothing can be done about it.
- login: "bll"
- mimetype: "text/plain"
- icomment:
Ticket change [db35f7bbc2] (rid 185301) by sebres on 2020-08-04 17:56:38:
- icomment:
> Is this trying to fix a vulnerability in Windows? Or Tcl? Basically both (or rather tcl's exec escape for windows, since an escape is already there, just it was wrong (vulnerable) before my fix in [21b0629c81] and it is still wrong (but not vulnerable anymore) now. And yes, I'll try to restore the backwards compatibility with preserving of the vulnerability fix simultaneously (as safe as possible). Your sentence from duplicate ticket "On Windows, the program should receive the arguments as is, as on windows, the programs parse the arguments, not the shell." is incorrect in my opinion, because in such a case the escape and quotation should be completely removed (belongs to the user task) but Tcl has from scratch tried to follow posix execv semantic, so had implement escape/quotation for windows simulating that (just partially, so not enough safe because impossibly).
- login: "sebres"
- mimetype: "text/x-fossil-wiki"
- icomment:
Ticket change [c56a667a2d] (rid 220795) by sebres on 2023-12-05 18:23:44:
- closedate changed to: "2460284.26648613"
- closer changed to: "sebres"
- icomment: "closed in [ee7ec33deb4d228f]"
- login: "sebres"
- mimetype: "text/x-fossil-wiki"
- resolution changed to: "Fixed"
- status changed to: "Closed"