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

Cross-Platform .rsp File Support #1016

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

lukaskohl-msft
Copy link
Collaborator

Unwrapping/expanding .rsp files used to be supported on Windows only due to FFI calling to shell32.dll. This PR removes FFI in favor of a code native solution.

the sarif-sdk submodule contains a reimplementation of CommandLineToArgvW. Rather than updating sarif-sdk, we've moved the relevant code into the BinSkim codebase, and pointed to the reimplementation instead to slightly lessen our reliance on sarif-sdk, while simultaneously increasing our supported platforms.

Alongside this change, tests were ported and altered over into the BinSkim codebase.

@lukaskohl-msft lukaskohl-msft requested a review from a team as a code owner October 10, 2024 09:23
@martin-reznik
Copy link
Collaborator

martin-reznik commented Oct 10, 2024 via email

Copy link
Contributor

@mkacmar mkacmar left a comment

Choose a reason for hiding this comment

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

I've left a few comments / questions.

src/BinSkim.Driver/ExpandArguments.cs Outdated Show resolved Hide resolved
src/BinSkim.Driver/ExpandArguments.cs Show resolved Hide resolved

private static bool IsResponseFileArgument(string argument)
{
return argument.Length > 1 && argument[0] == '@';
Copy link
Contributor

Choose a reason for hiding this comment

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

Nitpick: You may want to extract @ into some reasonably named constant.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Sure!

Lukas Kohl added 2 commits October 17, 2024 14:54
Example of an .rsp file:
"/example/to/binary/example.exe" # Binary
# ---- Libraries ----
"/example/to/libraries/library1.dll"
"/example/to/libraries/library2.dll"

would result in:
"/example/to/binary/example.exe"
"/example/to/libraries/library1.dll"
"/example/to/libraries/library2.dll"
Comment on lines +21 to +37
foreach (string argument in args)
{
string trimArgument = argument.Trim('"');
if (!IsResponseFileArgument(trimArgument))
{
expandedArguments.Add(trimArgument);
continue;
}

string responseFile = trimArgument.Substring(1);

responseFile = environmentVariables.ExpandEnvironmentVariables(responseFile);
responseFile = fileSystem.PathGetFullPath(responseFile);

string[] responseFileLines = fileSystem.FileReadAllLines(responseFile);
ExpandResponseFile(responseFileLines, expandedArguments);
}

Check notice

Code scanning / CodeQL

Missed opportunity to use Select Note

This foreach loop immediately
maps its iteration variable to another variable
- consider mapping the sequence explicitly using '.Select(...)'.
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.

3 participants