noclose.exe quoting is incompatible with cmd.exe quoting

Bug reports will be moved here when the described bug has been fixed

Moderators: Hacker, petermad, Stefan2, white

Post Reply
User avatar
MVV
Power Member
Power Member
Posts: 8711
Joined: 2008-08-03, 12:51 UTC
Location: Russian Federation

noclose.exe quoting is incompatible with cmd.exe quoting

Post by *MVV »

It is the fact that cmd.exe uses idiotic quoting system but all applications that start it have to follow its stupid rules.

The rule is that cmd.exe always strips first and last character of passed command line if these characters are double quotes. So this becomes wrong when your command line starts and ends with double quote.

E.g. you want to execute following command line:

Code: Select all

"C:\Program Files\UPX\UPX.exe" "D:\MyFile.exe"
Logical but wrong way of doing that with cmd.exe:

Code: Select all

cmd.exe /K "C:\Program Files\UPX\UPX.exe" "D:\MyFile.exe"
Here cmd.exe executes C:\Program because it cuts outer quotes and gets C:\Program Files\UPX\UPX.exe" "D:\MyFile.exe. Currently noclose.exe starts cmd.exe using this wrong syntax on Shift+Enter.

Stupid but proper way of doing that with cmd.exe (note extra quotes that are required for cmd.exe to be happy):

Code: Select all

cmd.exe /K ""C:\Program Files\UPX\UPX.exe" "D:\MyFile.exe""
This is applied to all Windows NT versions including Windows 2000, XP, 7, 8 - it is a more than 15 years story.
However it wasn't so for Windows 9x with its command.com command interpreter.
User avatar
Hacker
Moderator
Moderator
Posts: 13142
Joined: 2003-02-06, 14:56 UTC
Location: Bratislava, Slovakia

Post by *Hacker »

MVV,
The rabbit hole goes so much deeper. :|

Roman
Mal angenommen, du drückst Strg+F, wählst die FTP-Verbindung (mit gespeichertem Passwort), klickst aber nicht auf Verbinden, sondern fällst tot um.
User avatar
MVV
Power Member
Power Member
Posts: 8711
Joined: 2008-08-03, 12:51 UTC
Location: Russian Federation

Post by *MVV »

Wow, what a huge article! Some things are new to me, like inserting a double quote by inserting a pair of double quotes in a quoted string... Also I haven't noticed before that Unix is always passes argv arrays to process creating functions. BTW it is funny that only a page if about Unix and the rest pages are about Windows...

It's a pity that there are so many ways of handling command line arguments and quoting... I prefer simple parsing w\o ugly converting \" to ".

I can't understand the difference between pre-2008 and since-2008 double quoting behaviours: in both of them a pair of double quotes inside of a parameter inserts a double quote into that parameter and continue quoted string...
Got it: in pre-2008 behaviour a pair of double quotes ends quoted string.
User avatar
Hacker
Moderator
Moderator
Posts: 13142
Joined: 2003-02-06, 14:56 UTC
Location: Bratislava, Slovakia

Post by *Hacker »

MVV,
Wow, what a huge article!
Those are actually two articles. :D

Roman
Mal angenommen, du drückst Strg+F, wählst die FTP-Verbindung (mit gespeichertem Passwort), klickst aber nicht auf Verbinden, sondern fällst tot um.
User avatar
MVV
Power Member
Power Member
Posts: 8711
Joined: 2008-08-03, 12:51 UTC
Location: Russian Federation

Post by *MVV »

Hacker,
I was talking about second one, but first one is also big.
User avatar
ghisler(Author)
Site Admin
Site Admin
Posts: 50541
Joined: 2003-02-04, 09:46 UTC
Location: Switzerland
Contact:

Post by *ghisler(Author) »

Why is there a problem?
Author of Total Commander
https://www.ghisler.com
User avatar
MVV
Power Member
Power Member
Posts: 8711
Joined: 2008-08-03, 12:51 UTC
Location: Russian Federation

Post by *MVV »

ghisler,
Enter location with spaces in path, then Ctrl+Shift+Enter executable and then some files and press Shift+Enter - wrong command line will be executed because cmd.exe will cut outer quotes and break program path and last parameter. Isn't it a problem?

And anyway it is quite easy to fix: just add enclosing pair of double qoutes!
User avatar
ghisler(Author)
Site Admin
Site Admin
Posts: 50541
Joined: 2003-02-04, 09:46 UTC
Location: Switzerland
Contact:

Post by *ghisler(Author) »

Where should I add extra quotes, in TC when passing the parameter to noclose, or in noclose itself?
Author of Total Commander
https://www.ghisler.com
User avatar
MVV
Power Member
Power Member
Posts: 8711
Joined: 2008-08-03, 12:51 UTC
Location: Russian Federation

Post by *MVV »

In noclose itself:
cmd.exe /k "<exact command line from TC>"
Where command from TC comes as just entire noclose command line and is an absolutely correct command line like "c:\program files\upx\upx.exe" -d "c:\temp\1.exe".
User avatar
ghisler(Author)
Site Admin
Site Admin
Posts: 50541
Joined: 2003-02-04, 09:46 UTC
Location: Switzerland
Contact:

Post by *ghisler(Author) »

OK, could you check whether this does what you need?
https://plugins.ghisler.com/addons/noclose.zip
Author of Total Commander
https://www.ghisler.com
User avatar
MVV
Power Member
Power Member
Posts: 8711
Joined: 2008-08-03, 12:51 UTC
Location: Russian Federation

Post by *MVV »

It seems to be good with fixed noclose! Extra quotes make it working as expected!
User avatar
ghisler(Author)
Site Admin
Site Admin
Posts: 50541
Joined: 2003-02-04, 09:46 UTC
Location: Switzerland
Contact:

Post by *ghisler(Author) »

Thanks, I will include the new noclose in the first beta.
Author of Total Commander
https://www.ghisler.com
User avatar
MVV
Power Member
Power Member
Posts: 8711
Joined: 2008-08-03, 12:51 UTC
Location: Russian Federation

Post by *MVV »

Works fine in 8.52b1, thanks:)
Post Reply