Skip to content

LockData: Limit number of '|' chars that split the message#319

Closed
derrickstolee wants to merge 1 commit intomicrosoft:masterfrom
derrickstolee:lock-msg
Closed

LockData: Limit number of '|' chars that split the message#319
derrickstolee wants to merge 1 commit intomicrosoft:masterfrom
derrickstolee:lock-msg

Conversation

@derrickstolee
Copy link
Contributor

We send multiple data fields in our lock request and use the pipe symbol '|' to split these fields. However, the final field is free-text, so could include that symbol. We then complain when the length doesn't match.

Limit our splitting to be the expected number of fields, removing this issue. Add a simple unit test that verifies this behavior.

string[] dataParts = body.Split(new char[] { MessageSeparator }, count: 5);
int pid;
bool isElevated = false;
bool checkAvailabilityOnly = false;
Copy link
Member

Choose a reason for hiding this comment

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

We then complain when the length doesn't match.

Prior to your change, where was VFS for Git complaining that the length didn't match? The change looks OK to to me, but I can't see how the old code was running into problems.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Below, there is an exception for "Invalid lock message. The parsedCommand is an unexpected length, got: {0} from message: '{1}'".

Note further that we only complaint if dataParts.Length < 5 instead of succeeding in the correct way.

Most of the errors in the logs are off-by-one errors that were solved in #259.

Copy link
Member

Choose a reason for hiding this comment

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

I did see that check, but I couldn't see how extra | would break it.

As best I could tell parsedCommandLength shouldn't care about extra |, and the check is:

if (<header lengths> + parsedCommandLength) != <entire length of message>:

// ParsedCommandLength should be the length of the string at the end of the message
// Add the length of the previous parts, plus delimiters
int startingSpot = dataParts[0].Length + dataParts[1].Length + dataParts[2].Length + dataParts[3].Length + 4;
if ((startingSpot + parsedCommandLength) != body.Length)

There must be something I'm missing, any ideas?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah you're right! I guess I misread that we get the data from the full body instead of dataParts[4]. Undoing my production code change doesn't make the test fail. I'll close this PR.

Copy link
Member

Choose a reason for hiding this comment

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

I think the change you made to FromBody does make the code more readable and so if you still wanted to merge in the PR that'd be good with me.

I see we do have a unit test that already validates this scenario (look for // Verify strings with "|" will work) and so I'm not sure you'd need to merge that change in.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants