diff --git a/ReleaseHistory.md b/ReleaseHistory.md index 15fed48b..5de4ab14 100644 --- a/ReleaseHistory.md +++ b/ReleaseHistory.md @@ -16,9 +16,11 @@ - NEW => new feature ## 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. -* 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). * BUG: Fix `BA2027.EnableSourceLink` unexpectedly causes `ExceptionLoadingPdb` error when the PDB file is missing. [988](https://github.com/microsoft/binskim/pull/988). +* BUG: Exclude system-generated files `AssemblyAttributes.obj`, `AssemblyInfo.obj`, `stdafx.obj` from `BA2004.EnableSecureSourceCodeHashing`. [989](https://github.com/microsoft/binskim/pull/989). +* 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) +* NEW: `BA4002.ReportElfOrMachoCompilerData`, which collects telemetry data for Elf and Macho files, is now enabled by default. +* NEW: Add `--disable-telemetry` argument to disable telemetry collection. ## **v4.2.1** * FPS: `BA2004.EnableSecureSourceCodeHashing` now will no longer generate false positives on precompiled headers, they are always without hash. [#965](https://github.com/microsoft/binskim/pull/965) diff --git a/src/BinSkim.Rules/DwarfRules/BA4002.ReportElfOrMachoCompilerData.cs b/src/BinSkim.Rules/DwarfRules/BA4002.ReportElfOrMachoCompilerData.cs index cda2fb41..fca2a1a9 100644 --- a/src/BinSkim.Rules/DwarfRules/BA4002.ReportElfOrMachoCompilerData.cs +++ b/src/BinSkim.Rules/DwarfRules/BA4002.ReportElfOrMachoCompilerData.cs @@ -30,8 +30,6 @@ public class ReportElfOrMachoCompilerData : DwarfSkimmerBase, IOptionsProvider /// public override MultiformatMessageString FullDescription => new MultiformatMessageString { Text = RuleResources.BA4002_ReportELFCompilerData_Description }; - public override bool EnabledByDefault => false; - protected override IEnumerable MessageResourceNames => Array.Empty(); public override AnalysisApplicability CanAnalyzeDwarf(IDwarfBinary target, Sarif.PropertiesDictionary policy, out string reasonForNotAnalyzing) diff --git a/src/BinSkim.Rules/PERules/BA2004.EnableSecureSourceCodeHashing.cs b/src/BinSkim.Rules/PERules/BA2004.EnableSecureSourceCodeHashing.cs index 6bc92367..e1b44224 100644 --- a/src/BinSkim.Rules/PERules/BA2004.EnableSecureSourceCodeHashing.cs +++ b/src/BinSkim.Rules/PERules/BA2004.EnableSecureSourceCodeHashing.cs @@ -25,6 +25,11 @@ public class EnableSecureSourceCodeHashing : WindowsBinaryAndPdbSkimmerBase, IOp /// BA2004 /// public const string MSVCPredefinedTypesFileName = "predefined C++ types (compiler internal)"; + public const string MSVCCliAttributeTypesFileName = "CLI attribute types (compiler internal)"; + public const string MSVCStandardApplicationFrameworkFileName = "stdafx.obj"; + public const string AssemblyAttributesObjFileName = "AssemblyAttributes.obj"; + public const string AssemblyInfoObjFileName = "AssemblyInfo.obj"; + public override string Id => RuleIds.EnableSecureSourceCodeHashing; @@ -124,6 +129,13 @@ public void AnalyzeNativeBinaryAndPdb(BinaryAnalyzerContext context) continue; } + if (omDetails.Name.EndsWith(MSVCStandardApplicationFrameworkFileName) || + omDetails.Name.EndsWith(AssemblyAttributesObjFileName) || + omDetails.Name.EndsWith(AssemblyInfoObjFileName)) + { + continue; + } + bool isMsvc = (omDetails.WellKnownCompiler == WellKnownCompilers.MicrosoftC || omDetails.WellKnownCompiler == WellKnownCompilers.MicrosoftCxx); @@ -162,8 +174,9 @@ public void AnalyzeNativeBinaryAndPdb(BinaryAnalyzerContext context) string sfName = Path.GetFileName(sf.FileName); - // 1. Some compiler injected code that is listed as being in "predefined C++ types (compiler internal)" - if (sfName == MSVCPredefinedTypesFileName) + // 1. Some compiler injected code that is listed as being in + // "predefined C++ types (compiler internal)" or "CLI attribute types(compiler internal)". + if (sfName == MSVCPredefinedTypesFileName || sfName == MSVCCliAttributeTypesFileName) { continue; } diff --git a/src/BinSkim.Sdk/CompilerDataLogger.cs b/src/BinSkim.Sdk/CompilerDataLogger.cs index f930725d..d63aad84 100644 --- a/src/BinSkim.Sdk/CompilerDataLogger.cs +++ b/src/BinSkim.Sdk/CompilerDataLogger.cs @@ -109,9 +109,12 @@ public CompilerDataLogger(string sarifOutputFilePath, Sarif.SarifVersion sarifVe this.symbolPath = context.SymbolPath; this.telemetryClient = telemetry?.TelemetryClient; - bool forceOverwrite = context.ForceOverwrite; - string csvFilePath = context.Policy.GetProperty(CsvOutputPath); - CreateCsvOutputFile(csvFilePath, forceOverwrite); + if (!context.DisableTelemetry) + { + bool forceOverwrite = context.ForceOverwrite; + string csvFilePath = context.Policy.GetProperty(CsvOutputPath); + CreateCsvOutputFile(csvFilePath, forceOverwrite); + } // If the user has configured compiler telemetry collection, then we require analysis results // are persisted to a disk-based log file (to produce the telemetry 'summary' data persisted diff --git a/src/Test.FunctionalTests.BinSkim.Driver/BaselineTestData/Expected/MixedMode_x64_VS2013_Default.dll.sarif b/src/Test.FunctionalTests.BinSkim.Driver/BaselineTestData/Expected/MixedMode_x64_VS2013_Default.dll.sarif index e643b5a2..43c0f82b 100644 --- a/src/Test.FunctionalTests.BinSkim.Driver/BaselineTestData/Expected/MixedMode_x64_VS2013_Default.dll.sarif +++ b/src/Test.FunctionalTests.BinSkim.Driver/BaselineTestData/Expected/MixedMode_x64_VS2013_Default.dll.sarif @@ -98,7 +98,7 @@ "id": "Error_NativeWithInsecureDirectCompilands", "arguments": [ "MixedMode_x64_VS2013_Default.dll", - "Microsoft (R) Optimizing Compiler : cxx : 18.0.21005.1 : [directly linked] [MD5] (.NETFramework,Version=v4.5.AssemblyAttributes.obj,AssemblyInfo.obj,MixedMode_x64_VS2013_Default.obj)\r\n" + "Microsoft (R) Optimizing Compiler : cxx : 18.0.21005.1 : [directly linked] [MD5] (MixedMode_x64_VS2013_Default.obj)\r\n" ] }, "locations": [ diff --git a/src/Test.FunctionalTests.BinSkim.Driver/BaselineTestData/Expected/MixedMode_x64_VS2015_Default.exe.sarif b/src/Test.FunctionalTests.BinSkim.Driver/BaselineTestData/Expected/MixedMode_x64_VS2015_Default.exe.sarif index 4bc809ff..eec302f3 100644 --- a/src/Test.FunctionalTests.BinSkim.Driver/BaselineTestData/Expected/MixedMode_x64_VS2015_Default.exe.sarif +++ b/src/Test.FunctionalTests.BinSkim.Driver/BaselineTestData/Expected/MixedMode_x64_VS2015_Default.exe.sarif @@ -69,27 +69,6 @@ } ] }, - { - "ruleId": "BA2004", - "ruleIndex": 2, - "message": { - "id": "Warning_NativeWithInsecureStaticLibraryCompilands", - "arguments": [ - "MixedMode_x64_VS2015_Default.exe", - "Microsoft (R) Optimizing Compiler : cxx : 19.0.24215.1 : [directly linked] [No hash value present] (.NETFramework,Version=v4.5.2.AssemblyAttributes.obj,stdafx.obj)\r\n" - ] - }, - "locations": [ - { - "physicalLocation": { - "artifactLocation": { - "uri": "file:///Z:/src/Test.FunctionalTests.BinSkim.Driver/BaselineTestData/MixedMode_x64_VS2015_Default.exe", - "index": 0 - } - } - } - ] - }, { "ruleId": "BA2004", "ruleIndex": 2, @@ -98,7 +77,7 @@ "id": "Error_NativeWithInsecureDirectCompilands", "arguments": [ "MixedMode_x64_VS2015_Default.exe", - "Microsoft (R) Optimizing Compiler : cxx : 19.0.24215.1 : [directly linked] [MD5] (AssemblyInfo.obj,MixedMode_x64_VS2015_Default.obj)\r\n" + "Microsoft (R) Optimizing Compiler : cxx : 19.0.24215.1 : [directly linked] [MD5] (MixedMode_x64_VS2015_Default.obj)\r\n" ] }, "locations": [ diff --git a/src/Test.FunctionalTests.BinSkim.Driver/BaselineTestData/Expected/MixedMode_x64_VS2019_CPlusPlus_DEBUG_DEFAULT.dll.sarif b/src/Test.FunctionalTests.BinSkim.Driver/BaselineTestData/Expected/MixedMode_x64_VS2019_CPlusPlus_DEBUG_DEFAULT.dll.sarif index a5bd538e..3832f7f2 100644 --- a/src/Test.FunctionalTests.BinSkim.Driver/BaselineTestData/Expected/MixedMode_x64_VS2019_CPlusPlus_DEBUG_DEFAULT.dll.sarif +++ b/src/Test.FunctionalTests.BinSkim.Driver/BaselineTestData/Expected/MixedMode_x64_VS2019_CPlusPlus_DEBUG_DEFAULT.dll.sarif @@ -69,27 +69,6 @@ } ] }, - { - "ruleId": "BA2004", - "ruleIndex": 2, - "message": { - "id": "Warning_NativeWithInsecureStaticLibraryCompilands", - "arguments": [ - "MixedMode_x64_VS2019_CPlusPlus_DEBUG_DEFAULT.dll", - "Microsoft (R) Optimizing Compiler : cxx : 19.29.30133.0 : [directly linked] [No hash value present] (.NETFramework,Version=v4.0.AssemblyAttributes.obj)\r\n" - ] - }, - "locations": [ - { - "physicalLocation": { - "artifactLocation": { - "uri": "file:///Z:/src/Test.FunctionalTests.BinSkim.Driver/BaselineTestData/MixedMode_x64_VS2019_CPlusPlus_DEBUG_DEFAULT.dll", - "index": 0 - } - } - } - ] - }, { "ruleId": "BA2004", "ruleIndex": 2, diff --git a/src/Test.FunctionalTests.BinSkim.Driver/BaselineTestData/Expected/MixedMode_x64_VS2019_CPlusPlus_DEBUG_FASTLINK.dll.sarif b/src/Test.FunctionalTests.BinSkim.Driver/BaselineTestData/Expected/MixedMode_x64_VS2019_CPlusPlus_DEBUG_FASTLINK.dll.sarif index 5f298732..b47a0fbc 100644 --- a/src/Test.FunctionalTests.BinSkim.Driver/BaselineTestData/Expected/MixedMode_x64_VS2019_CPlusPlus_DEBUG_FASTLINK.dll.sarif +++ b/src/Test.FunctionalTests.BinSkim.Driver/BaselineTestData/Expected/MixedMode_x64_VS2019_CPlusPlus_DEBUG_FASTLINK.dll.sarif @@ -69,27 +69,6 @@ } ] }, - { - "ruleId": "BA2004", - "ruleIndex": 2, - "message": { - "id": "Warning_NativeWithInsecureStaticLibraryCompilands", - "arguments": [ - "MixedMode_x64_VS2019_CPlusPlus_DEBUG_FASTLINK.dll", - "Microsoft (R) Optimizing Compiler : cxx : 19.29.30133.0 : [directly linked] [No hash value present] (.NETFramework,Version=v4.0.AssemblyAttributes.obj)\r\n" - ] - }, - "locations": [ - { - "physicalLocation": { - "artifactLocation": { - "uri": "file:///Z:/src/Test.FunctionalTests.BinSkim.Driver/BaselineTestData/MixedMode_x64_VS2019_CPlusPlus_DEBUG_FASTLINK.dll", - "index": 0 - } - } - } - ] - }, { "ruleId": "BA2004", "ruleIndex": 2, diff --git a/src/Test.FunctionalTests.BinSkim.Driver/BaselineTestData/Expected/MixedMode_x64_VS2019_CPlusPlus_DEBUG_FULL.dll.sarif b/src/Test.FunctionalTests.BinSkim.Driver/BaselineTestData/Expected/MixedMode_x64_VS2019_CPlusPlus_DEBUG_FULL.dll.sarif index eb73cba5..aad62053 100644 --- a/src/Test.FunctionalTests.BinSkim.Driver/BaselineTestData/Expected/MixedMode_x64_VS2019_CPlusPlus_DEBUG_FULL.dll.sarif +++ b/src/Test.FunctionalTests.BinSkim.Driver/BaselineTestData/Expected/MixedMode_x64_VS2019_CPlusPlus_DEBUG_FULL.dll.sarif @@ -69,27 +69,6 @@ } ] }, - { - "ruleId": "BA2004", - "ruleIndex": 2, - "message": { - "id": "Warning_NativeWithInsecureStaticLibraryCompilands", - "arguments": [ - "MixedMode_x64_VS2019_CPlusPlus_DEBUG_FULL.dll", - "Microsoft (R) Optimizing Compiler : cxx : 19.29.30133.0 : [directly linked] [No hash value present] (.NETFramework,Version=v4.0.AssemblyAttributes.obj)\r\n" - ] - }, - "locations": [ - { - "physicalLocation": { - "artifactLocation": { - "uri": "file:///Z:/src/Test.FunctionalTests.BinSkim.Driver/BaselineTestData/MixedMode_x64_VS2019_CPlusPlus_DEBUG_FULL.dll", - "index": 0 - } - } - } - ] - }, { "ruleId": "BA2004", "ruleIndex": 2, diff --git a/src/Test.FunctionalTests.BinSkim.Driver/BaselineTestData/Expected/MixedMode_x86_VS2013_Default.exe.sarif b/src/Test.FunctionalTests.BinSkim.Driver/BaselineTestData/Expected/MixedMode_x86_VS2013_Default.exe.sarif index 368c9d01..2a81700f 100644 --- a/src/Test.FunctionalTests.BinSkim.Driver/BaselineTestData/Expected/MixedMode_x86_VS2013_Default.exe.sarif +++ b/src/Test.FunctionalTests.BinSkim.Driver/BaselineTestData/Expected/MixedMode_x86_VS2013_Default.exe.sarif @@ -47,27 +47,6 @@ } ] }, - { - "ruleId": "BA2004", - "ruleIndex": 1, - "message": { - "id": "Warning_NativeWithInsecureStaticLibraryCompilands", - "arguments": [ - "MixedMode_x86_VS2013_Default.exe", - "Microsoft (R) Optimizing Compiler : cxx : 18.0.21005.1 : [directly linked] [No hash value present] (stdafx.obj)\r\n" - ] - }, - "locations": [ - { - "physicalLocation": { - "artifactLocation": { - "uri": "file:///Z:/src/Test.FunctionalTests.BinSkim.Driver/BaselineTestData/MixedMode_x86_VS2013_Default.exe", - "index": 0 - } - } - } - ] - }, { "ruleId": "BA2004", "ruleIndex": 1, @@ -76,7 +55,7 @@ "id": "Error_NativeWithInsecureDirectCompilands", "arguments": [ "MixedMode_x86_VS2013_Default.exe", - "Microsoft (R) Optimizing Compiler : cxx : 18.0.21005.1 : [directly linked] [MD5] (.NETFramework,Version=v4.5.AssemblyAttributes.obj,AssemblyInfo.obj,MixedMode_x86_VS2013_Default.obj)\r\n" + "Microsoft (R) Optimizing Compiler : cxx : 18.0.21005.1 : [directly linked] [MD5] (MixedMode_x86_VS2013_Default.obj)\r\n" ] }, "locations": [ diff --git a/src/Test.FunctionalTests.BinSkim.Driver/BaselineTestData/Expected/MixedMode_x86_VS2015_Default.exe.sarif b/src/Test.FunctionalTests.BinSkim.Driver/BaselineTestData/Expected/MixedMode_x86_VS2015_Default.exe.sarif index a8c134f9..689eb08f 100644 --- a/src/Test.FunctionalTests.BinSkim.Driver/BaselineTestData/Expected/MixedMode_x86_VS2015_Default.exe.sarif +++ b/src/Test.FunctionalTests.BinSkim.Driver/BaselineTestData/Expected/MixedMode_x86_VS2015_Default.exe.sarif @@ -47,27 +47,6 @@ } ] }, - { - "ruleId": "BA2004", - "ruleIndex": 1, - "message": { - "id": "Warning_NativeWithInsecureStaticLibraryCompilands", - "arguments": [ - "MixedMode_x86_VS2015_Default.exe", - "Microsoft (R) Optimizing Compiler : cxx : 19.0.24215.1 : [directly linked] [No hash value present] (.NETFramework,Version=v4.5.2.AssemblyAttributes.obj,stdafx.obj)\r\n" - ] - }, - "locations": [ - { - "physicalLocation": { - "artifactLocation": { - "uri": "file:///Z:/src/Test.FunctionalTests.BinSkim.Driver/BaselineTestData/MixedMode_x86_VS2015_Default.exe", - "index": 0 - } - } - } - ] - }, { "ruleId": "BA2004", "ruleIndex": 1, @@ -76,7 +55,7 @@ "id": "Error_NativeWithInsecureDirectCompilands", "arguments": [ "MixedMode_x86_VS2015_Default.exe", - "Microsoft (R) Optimizing Compiler : cxx : 19.0.24215.1 : [directly linked] [MD5] (AssemblyInfo.obj,MixedMode_x86_VS2015_Default.obj)\r\n" + "Microsoft (R) Optimizing Compiler : cxx : 19.0.24215.1 : [directly linked] [MD5] (MixedMode_x86_VS2015_Default.obj)\r\n" ] }, "locations": [ diff --git a/src/Test.FunctionalTests.BinSkim.Driver/BaselineTestData/Expected/Native_x64_VS2013_Default.dll.sarif b/src/Test.FunctionalTests.BinSkim.Driver/BaselineTestData/Expected/Native_x64_VS2013_Default.dll.sarif index a4502faf..3536d94b 100644 --- a/src/Test.FunctionalTests.BinSkim.Driver/BaselineTestData/Expected/Native_x64_VS2013_Default.dll.sarif +++ b/src/Test.FunctionalTests.BinSkim.Driver/BaselineTestData/Expected/Native_x64_VS2013_Default.dll.sarif @@ -77,7 +77,7 @@ "id": "Error_NativeWithInsecureDirectCompilands", "arguments": [ "Native_x64_VS2013_Default.dll", - "Microsoft (R) Optimizing Compiler : cxx : 18.0.21005.1 : [directly linked] [MD5] (dllmain.obj,Native_x64_VS2013_Default.obj,stdafx.obj)\r\n" + "Microsoft (R) Optimizing Compiler : cxx : 18.0.21005.1 : [directly linked] [MD5] (dllmain.obj,Native_x64_VS2013_Default.obj)\r\n" ] }, "locations": [ diff --git a/src/Test.FunctionalTests.BinSkim.Driver/BaselineTestData/Expected/Native_x64_VS2015_Default.dll.sarif b/src/Test.FunctionalTests.BinSkim.Driver/BaselineTestData/Expected/Native_x64_VS2015_Default.dll.sarif index d31483c4..6a2dc56c 100644 --- a/src/Test.FunctionalTests.BinSkim.Driver/BaselineTestData/Expected/Native_x64_VS2015_Default.dll.sarif +++ b/src/Test.FunctionalTests.BinSkim.Driver/BaselineTestData/Expected/Native_x64_VS2015_Default.dll.sarif @@ -77,7 +77,7 @@ "id": "Error_NativeWithInsecureDirectCompilands", "arguments": [ "Native_x64_VS2015_Default.dll", - "Microsoft (R) Optimizing Compiler : cxx : 19.0.23026.0 : [directly linked] [MD5] (dllmain.obj,Native_x64_VS2015_Default.obj,stdafx.obj)\r\n" + "Microsoft (R) Optimizing Compiler : cxx : 19.0.23026.0 : [directly linked] [MD5] (dllmain.obj,Native_x64_VS2015_Default.obj)\r\n" ] }, "locations": [ diff --git a/src/Test.FunctionalTests.BinSkim.Driver/BaselineTestData/Expected/Native_x86_VS2013_Default.exe.sarif b/src/Test.FunctionalTests.BinSkim.Driver/BaselineTestData/Expected/Native_x86_VS2013_Default.exe.sarif index e453f1b8..38e4f0cb 100644 --- a/src/Test.FunctionalTests.BinSkim.Driver/BaselineTestData/Expected/Native_x86_VS2013_Default.exe.sarif +++ b/src/Test.FunctionalTests.BinSkim.Driver/BaselineTestData/Expected/Native_x86_VS2013_Default.exe.sarif @@ -33,7 +33,7 @@ "id": "Warning_NativeWithInsecureStaticLibraryCompilands", "arguments": [ "Native_x86_VS2013_Default.exe", - "Microsoft (R) Optimizing Compiler : c : 18.0.20806.0 : MSVCRTD.lib [MD5] (_newmode.obj,atonexit.obj,chandler4gs.obj,cinitexe.obj,fp8.obj,gs_cookie.obj,gs_report.obj,gs_support.obj,loadcfg.obj,merr.obj,natstart.obj,pesect.obj,secchk.obj,wcrtexew.obj,wdllargv.obj,wildcard.obj,xncommod.obj,xthdloc.obj,xtxtmode.obj)\r\nMicrosoft (R) Optimizing Compiler : cxx : 18.0.20806.0 : atls.lib [MD5] (atlbase.obj,stdafx.obj)\r\nMicrosoft (R) Optimizing Compiler : cxx : 18.0.20806.0 : MSVCRTD.lib [MD5] (ehvecdtr.obj,error.obj,init.obj,initsect.obj,pdblkup.obj,stack.obj,ti_inst.obj,unhandld.obj,userapi.obj)\r\n" + "Microsoft (R) Optimizing Compiler : c : 18.0.20806.0 : MSVCRTD.lib [MD5] (_newmode.obj,atonexit.obj,chandler4gs.obj,cinitexe.obj,fp8.obj,gs_cookie.obj,gs_report.obj,gs_support.obj,loadcfg.obj,merr.obj,natstart.obj,pesect.obj,secchk.obj,wcrtexew.obj,wdllargv.obj,wildcard.obj,xncommod.obj,xthdloc.obj,xtxtmode.obj)\r\nMicrosoft (R) Optimizing Compiler : cxx : 18.0.20806.0 : atls.lib [MD5] (atlbase.obj)\r\nMicrosoft (R) Optimizing Compiler : cxx : 18.0.20806.0 : MSVCRTD.lib [MD5] (ehvecdtr.obj,error.obj,init.obj,initsect.obj,pdblkup.obj,stack.obj,ti_inst.obj,unhandld.obj,userapi.obj)\r\n" ] }, "locations": [ @@ -55,7 +55,7 @@ "id": "Error_NativeWithInsecureDirectCompilands", "arguments": [ "Native_x86_VS2013_Default.exe", - "Microsoft (R) Optimizing Compiler : cxx : 18.0.21005.1 : [directly linked] [MD5] (Native_x86_VS2013_Default.obj,stdafx.obj)\r\n" + "Microsoft (R) Optimizing Compiler : cxx : 18.0.21005.1 : [directly linked] [MD5] (Native_x86_VS2013_Default.obj)\r\n" ] }, "locations": [ diff --git a/src/Test.FunctionalTests.BinSkim.Driver/BaselineTestData/Expected/Native_x86_VS2015_Default.exe.sarif b/src/Test.FunctionalTests.BinSkim.Driver/BaselineTestData/Expected/Native_x86_VS2015_Default.exe.sarif index 9979db4c..c8adfce7 100644 --- a/src/Test.FunctionalTests.BinSkim.Driver/BaselineTestData/Expected/Native_x86_VS2015_Default.exe.sarif +++ b/src/Test.FunctionalTests.BinSkim.Driver/BaselineTestData/Expected/Native_x86_VS2015_Default.exe.sarif @@ -55,7 +55,7 @@ "id": "Error_NativeWithInsecureDirectCompilands", "arguments": [ "Native_x86_VS2015_Default.exe", - "Microsoft (R) Optimizing Compiler : cxx : 19.0.23026.0 : [directly linked] [MD5] (Native_x86_VS2015_Default.obj,stdafx.obj)\r\n" + "Microsoft (R) Optimizing Compiler : cxx : 19.0.23026.0 : [directly linked] [MD5] (Native_x86_VS2015_Default.obj)\r\n" ] }, "locations": [ diff --git a/src/Test.FunctionalTests.BinSkim.Driver/BaselineTestData/Expected/Native_x86_VS2015_Default_Debug.dll.sarif b/src/Test.FunctionalTests.BinSkim.Driver/BaselineTestData/Expected/Native_x86_VS2015_Default_Debug.dll.sarif index 21348959..1d002c1e 100644 --- a/src/Test.FunctionalTests.BinSkim.Driver/BaselineTestData/Expected/Native_x86_VS2015_Default_Debug.dll.sarif +++ b/src/Test.FunctionalTests.BinSkim.Driver/BaselineTestData/Expected/Native_x86_VS2015_Default_Debug.dll.sarif @@ -55,7 +55,7 @@ "id": "Error_NativeWithInsecureDirectCompilands", "arguments": [ "Native_x86_VS2015_Default_Debug.dll", - "Microsoft (R) Optimizing Compiler : cxx : 19.0.24215.1 : [directly linked] [MD5] (dllmain.obj,Native_x86_VS2015_Default_Debug.obj,stdafx.obj)\r\n" + "Microsoft (R) Optimizing Compiler : cxx : 19.0.24215.1 : [directly linked] [MD5] (dllmain.obj,Native_x86_VS2015_Default_Debug.obj)\r\n" ] }, "locations": [ diff --git a/src/Test.UnitTests.BinSkim.Driver/TelemetryTests.cs b/src/Test.UnitTests.BinSkim.Driver/TelemetryTests.cs index c8ee9ce0..66811f69 100644 --- a/src/Test.UnitTests.BinSkim.Driver/TelemetryTests.cs +++ b/src/Test.UnitTests.BinSkim.Driver/TelemetryTests.cs @@ -119,5 +119,54 @@ public void Telemetry_ShouldHaveConsistentResultsEnabledOrDisabled() "Whether DisableTelemetry is explicitly set to false or not, the results should be the same."); } } + + [Fact] + public void Telemetry_ReportElfOrMachoCompilerData_EnabledAndWorkingByDefault() + { + if (!PlatformSpecificHelpers.RunningOnWindows()) { return; } + + using var assertionScope = new AssertionScope(); + + string sarifFile = Path.Combine(Path.GetTempPath(), "AnalyzeCommand_Telemetry_ReportElfOrMachoCompilerData_EnabledByDefault.sarif"); + string csvFile = Path.Combine(Path.GetTempPath(), "AnalyzeCommand_Telemetry_ReportElfOrMachoCompilerData_EnabledByDefault.csv"); + string configFile = Path.Combine(Path.GetTempPath(), "AnalyzeCommand_Telemetry_ReportElfOrMachoCompilerData_EnabledByDefault.xml"); + + File.Delete(sarifFile); + File.Delete(csvFile); + File.Delete(configFile); + + string configFileContent = $""; + File.WriteAllText(configFile, configFileContent); + + string pathToTestFile = Path.Combine(PEBinaryTests.TestData, "Dwarf", "hello-dwarf5-o2"); + var options = new AnalyzeOptions + { + TargetFileSpecifiers = new string[] { + pathToTestFile + }, + OutputFilePath = sarifFile, + OutputFileOptions = new[] { FilePersistenceOptions.ForceOverwrite }, + DataToInsert = new[] { OptionallyEmittedData.Hashes }, + ConfigurationFilePath = configFile, + }; + + var command = new MultithreadedAnalyzeCommand(); + command.Run(options); + + bool fileExists = File.Exists(csvFile); + fileExists.Should().BeTrue("because the telemetry is enabled"); + + if (fileExists) + { + string fileContent = File.ReadAllText(csvFile); + fileContent.Should().Contain("-gdwarf-5", "because the rule ReportElfOrMachoCompilerData is enabled by default"); + } + + File.Delete(csvFile); + options.DisableTelemetry = true; + command.Run(options); + fileExists = File.Exists(csvFile); + fileExists.Should().BeFalse("because the telemetry is disabled"); + } } }