Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed a regex matching bug. #217

Merged
merged 4 commits into from
Nov 22, 2023

Conversation

LiYueqian-James
Copy link
Contributor

When the command is a raw file path, using the file path as a regex pattern can cause exceptions (E.g. "C://Users//..., /u is interpreted as a hexadecimal group).

Consider the following example:

ProcessManager.Processes[1] = process(fullCmd: C://Users//Setup1.exe)
ProcessManager.Processes[2] = process(fullCmd: C://Users//Setup2.exe)
command = C://Users//Setup2.exe

Line 93 is expected to return "C://Users//Setup2.exe". However, when FirstOrDefault compares the first two cmds, because
Regex.IsMatch("C://Users//Setup1.exe", "C://Users//Setup2.exe") throws an "Insufficient hexadecimal digits" exception due to the "\u", FirstOrDefault will not check the second process's full cmd, resulting in an unexpected failure/exception.

The proposed change modifies the execution order. FirstorDefault will first iterate through all the processes and see if there is a complete raw string matching. If there is no such matching, continue with regex matching.

@yangpanMS yangpanMS merged commit b4477a4 into microsoft:main Nov 22, 2023
muskankhedia pushed a commit to muskankhedia/VirtualClient that referenced this pull request Nov 24, 2023
* fixed a regex matching bug

* working dir

---------

Co-authored-by: Yang Pan <[email protected]>
@LiYueqian-James LiYueqian-James deleted the yueqianli/unitTestingBug branch December 29, 2023 02:17
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