[vbox-dev] Regarding possible solution to #13157 - Windows Command line argument handling error

Magnus Madsen madsen.magnus at gmail.com
Tue Apr 21 15:30:25 GMT 2015


Hi!

I have been investigating ticket 13157 regarding quotes in arguments, since
the error is interfering with an application I am developing.

I have identified the problem and solved it in source, but before I work on
submitting any patches I want to make sure that I am not misunderstanding
something and that the changes do not break anything.

Note that I have not tested using Unix, guest or host, so I cannot comment
on the handling of command-line arguments for that platform.

Quick recap of the problem: When starting a new guest process, any
command-line arguments that contain double quotes are incorrectly sent to
the process as they are replaced with backslashes.

An example would be the argument
TRANSFORMS="C:\path to file"
being replaced with
TRANSFORMS=\C:\path to file\

As far as I can tell, this error is a combination of two problems.

Both in VBox\Runtime\common\misc\getoptargv.cpp

* RTGetOptArgvFromString
The function splits a string into an array of arguments but does not
correctly handle double quotes within a string.

Give it the following input:
argument1 "argument2=\"test\""

And you will get:
[0] argument1
[1] argument2=\test\

The problem seems to be that the function strips double quotes from the
input string and does not take into account that they might be a part of an
argument, rather than enclosing an argument.
I have modified this behavior to only consider non-escaped double quotes as
enclosing arguments and include backslash-escaped double quotes in the
output string.

This gives the result:
[0] argument1
[1] argument2="test"


This is the first part of the problem, however it isn't the whole story
because there are also problems with the function that creates the argument
string used for starting a new process.

The RTGetOptArgvToString function performs this action, and what it does is
always enclose arguments that contain characters that should be escaped in
double quotes.
Take the following argument array as an example:

[0] argument="C:\path to file\filename.dat"

Because of the space in the argument, RTGetOptArgvToString will output the
following argument string:
"argument="C:\path to file\filename.dat""

Some applications, notably MSIEXEC, does not handle this double quotation
and I do not see it being necessary.
I modified the rtGetOpArgvRequiresQuoting function which
RTGetOptArgvToString uses to determine if an argument should be escaped to,
so that it only returns true if the argument contains characters that
should be escaped that are not enclosed in double quotes.

This made me a little unsure of the necessity of the escaping in
RTGetOptArgvToString though - it seems as though everything is escaped as
required by the command-line interpreter (>< etc.) and to my knowledge this
is not necessary when creating processes directly as the Guest Additions do.

I realize this is a lot of input on an error that affects very few users,
but I would appreciate any feedback that could assist me in creating a
suitable patch for this issue.

Kind regards,
Magnus
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.virtualbox.org/pipermail/vbox-dev/attachments/20150421/c27fcf9b/attachment.html>


More information about the vbox-dev mailing list