Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2217,7 +2217,35 @@ private static string[] ParseArgv(ProcessStartInfo psi)
{
var argvList = new List<string>();
argvList.Add(psi.FileName);
argvList.AddRange(psi.Arguments.Split(' '));

var argsToParse = psi.Arguments.Trim();
var argsLength = argsToParse.Length;
for (int i=0; i<argsLength; )
{
var iStart = i;

switch (argsToParse[i])
{
case '"':
// Special case for arguments within quotes
// Just return argument value within the quotes
while ((++i < argsLength) && argsToParse[i] != '"') { };
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there enforcement for the string ending in a '"'? Does that happen in a different layer?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No enforcement here. This expects the argument string to be correctly formatted. If it is not then the argument list is wrong and any errors are generated when the process is created.

This is currently scoped internally so we currently have complete control in how it is used. However, I did intend this to be robust against malformed strings (empty, single quote, unmatched quotes, single space, only spaces, etc.). If you see something I missed please let me know.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My initial concern regarded unmatched double quotes. Thinking about it some more, two other things came to mind:

  1. Strings that use single quotes
  2. Argument lists that include other commands. Do we do validation on it? I'm wondering about something like this: arg1 arg2; rm -rf *

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Single quotes are not supported and not needed. It is something we could add if we need it in the future. Argument validation is not intended to be performed here. This just parses space delimited strings with a special case for double quoted arguments.

I just tried to make sure it doesn't blow up with malformed strings and cause an access violation or null reference exception.

if (iStart < argsLength - 1)
{
iStart++;
}
break;

default:
// Common case for parsing arguments with space character delimiter
while ((++i < argsLength) && argsToParse[i] != ' ') { };
break;
}

argvList.Add(argsToParse.Substring(iStart, (i-iStart)));
while ((++i < argsLength) && argsToParse[i] == ' ') { };
}

return argvList.ToArray();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1461,6 +1461,12 @@ internal override void CreateAsync()
StartReaderThread(_stdOutReader);
}

internal override void CloseAsync()
{
base.CloseAsync();
CloseConnection();
}

#endregion

#region Private Methods
Expand Down