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

* FPS: BA2004.EnableSecureSourceCodeHashing now will no longer generate false positives for UWP App regarding dummy.obj. #987

Merged
merged 6 commits into from
Apr 29, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 1 addition & 0 deletions ReleaseHistory.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
## UNRELEASED
* DEP: Update `Sarif.Sdk` submodule from [bc8cb57 to fd6e615](https://github.com/microsoft/sarif-sdk/compare/bc8cb57...fd6e615). Reference [SARIF SDK Release History](https://github.com/microsoft/sarif-sdk/blob/fd6e615/ReleaseHistory.md).
* NEW: Add `--disable-telemetry` argument to disable telemetry collection.
* FPS: `BA2004.EnableSecureSourceCodeHashing` now will no longer generate false positives for UWP App regarding `dummy.obj`. [#976](https://github.com/microsoft/binskim/pull/976)
shaopeng-gh marked this conversation as resolved.
Show resolved Hide resolved
* BUG: Fix `ERR998.ExceptionInAnalyze`: `InvalidOperationException: Unrecognized crypto HRESULT: 0x80096011` for check `BA2022.SignSecurely` when the signature is malformed, by adding missing error code to error description mappings. [969](https://github.com/microsoft/binskim/pull/969)

## **v4.2.1**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,11 @@ public void AnalyzeNativeBinaryAndPdb(BinaryAnalyzerContext context)
continue;
}

if (IsLikelyUwpDummyObj(omDetails.Language, omDetails.Library, omDetails.Name))
{
continue;
}

bool isMsvc = (omDetails.WellKnownCompiler == WellKnownCompilers.MicrosoftC ||
omDetails.WellKnownCompiler == WellKnownCompilers.MicrosoftCxx);

Expand Down Expand Up @@ -297,5 +302,8 @@ public IEnumerable<IOption> GetOptions()
// RequiredCompilerWarnings,
}.ToImmutableArray();
}

internal static bool IsLikelyUwpDummyObj(Language language, string library, string name) =>
language == Language.MASM && library?.Equals(name) == true && library == @"c:\dummy.obj";

Choose a reason for hiding this comment

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

string.Equals call should specify StringComparison, presumably .Ordinal.
Drop "== true"
Don't use == comparison with strings (language and library). Use .Equals with a comparison specified.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

fixed.
can not Drop "== true" because there is null check. But I moved it out now so more clear.

}
}
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using FluentAssertions;

using Microsoft.CodeAnalysis.BinaryParsers.ProgramDatabase;

using Xunit;

namespace Microsoft.CodeAnalysis.IL.Rules
{
public class EnableSecureSourceCodeHashingTests
{
[Fact]
public void IsLikelyUwpDummyObjTests()
{
EnableSecureSourceCodeHashing.IsLikelyUwpDummyObj(Language.MASM, @"c:\dummy.obj", @"c:\dummy.obj").Should().BeTrue();
EnableSecureSourceCodeHashing.IsLikelyUwpDummyObj(Language.MASM, @"d:\dummy.obj", @"d:\dummy.obj").Should().BeFalse();
Copy link
Collaborator

Choose a reason for hiding this comment

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

@shaopeng-gh To make sure I understand this correctly, d:\dummy.obj should result in false? The drive letter must be c?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yes I believe the official one should have the path fixed as c:\dummy.obj

EnableSecureSourceCodeHashing.IsLikelyUwpDummyObj(Language.C, @"c:\dummy.obj", @"c:\dummy.obj").Should().BeFalse();
EnableSecureSourceCodeHashing.IsLikelyUwpDummyObj(Language.MASM, @"c:\Dummy.obj", @"c:\Dummy.obj").Should().BeFalse();
EnableSecureSourceCodeHashing.IsLikelyUwpDummyObj(Language.MASM, "AnyLib", @"c:\dummy.obj").Should().BeFalse();
}
}
}
Loading