Skip to content

Commit 1bb4191

Browse files
author
Pavel Bansky
committed
Added support for sarif
1 parent b16c31b commit 1bb4191

File tree

4 files changed

+28
-2065
lines changed

4 files changed

+28
-2065
lines changed

src/Microsoft.DevSkim/Microsoft.DevSkim.CLI/Microsoft.DevSkim.CLI.csproj

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,13 @@
99
<ApplicationIcon />
1010
<PackageId>Microsoft.DevSkim.CLI</PackageId>
1111
<Product>Microsoft DevSkim Command Line Interface</Product>
12-
<Version>0.1.9</Version>
12+
<Version>0.1.10</Version>
1313
<Authors>Microsoft</Authors>
1414
<Company>Microsoft</Company>
1515
<Copyright>(c) Microsoft Corporation. All rights reserved</Copyright>
1616
<Description>DevSkim is a framework and Language analyzer that provide inline security analysis</Description>
1717
</PropertyGroup>
1818

19-
<ItemGroup>
20-
<None Remove="Resources\devskim-rules.json" />
21-
<None Remove="soubor.txt" />
22-
</ItemGroup>
23-
2419
<ItemGroup>
2520
<EmbeddedResource Include="Resources\devskim-rules.json" />
2621
</ItemGroup>

src/Microsoft.DevSkim/Microsoft.DevSkim.CLI/Resources/devskim-rules.json

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
"rule_info": "DS185832.md",
5252
"patterns": [
5353
{
54-
"pattern": "\\bstrcpy\\s*\\(([^,]+),([^,]+)\\)",
54+
"pattern": "\\bstrcpy\\s*\\(([^,]+),([^,]+?)\\)",
5555
"type": "regex",
5656
"modifiers": null,
5757
"scopes": [
@@ -66,7 +66,7 @@
6666
"name": "Change to strcpy_s (Recommended for VC++)",
6767
"type": "regex-replace",
6868
"pattern": {
69-
"pattern": "\\bstrcpy\\s*\\(([^,]+),([^,]+)\\)",
69+
"pattern": "\\bstrcpy\\s*\\(([^,]+),([^,]+?)\\)",
7070
"type": "regex",
7171
"modifiers": null,
7272
"scopes": [
@@ -80,7 +80,7 @@
8080
"name": "Change to strlcpy",
8181
"type": "regex-replace",
8282
"pattern": {
83-
"pattern": "\\bstrcpy\\s*\\(([^,]+),([^,]+)\\)",
83+
"pattern": "\\bstrcpy\\s*\\(([^,]+),([^,]+?)\\)",
8484
"type": "regex",
8585
"modifiers": null,
8686
"scopes": [
@@ -113,7 +113,7 @@
113113
"rule_info": "DS111237.md",
114114
"patterns": [
115115
{
116-
"pattern": "\\bstrncpy\\s*\\(([^,]+),([^,]+),([^,]+)\\)+",
116+
"pattern": "\\bstrncpy\\s*\\(([^,]+),([^,]+),([^,]+?)\\)+",
117117
"type": "regex",
118118
"modifiers": null,
119119
"scopes": [
@@ -128,7 +128,7 @@
128128
"name": "Change to strcpy_s (Recommended for VC++)",
129129
"type": "regex-replace",
130130
"pattern": {
131-
"pattern": "\\bstrncpy\\s*\\(([^,]+),([^,]+),([^,]+)\\)+",
131+
"pattern": "\\bstrncpy\\s*\\(([^,]+),([^,]+),([^,]+?)\\)+",
132132
"type": "regex",
133133
"modifiers": null,
134134
"scopes": [
@@ -142,7 +142,7 @@
142142
"name": "Change to strlcpy",
143143
"type": "regex-replace",
144144
"pattern": {
145-
"pattern": "\\bstrncpy\\s*\\(([^,]+),([^,]+),([^,]+)\\)+",
145+
"pattern": "\\bstrncpy\\s*\\(([^,]+),([^,]+),([^,]+?)\\)+",
146146
"type": "regex",
147147
"modifiers": null,
148148
"scopes": [
@@ -175,7 +175,7 @@
175175
"rule_info": "DS141863.md",
176176
"patterns": [
177177
{
178-
"pattern": "\\bstrcat\\s*\\(([^,]+),([^,]+)\\)",
178+
"pattern": "\\bstrcat\\s*\\(([^,]+),([^,]+?)\\)",
179179
"type": "regex",
180180
"modifiers": null,
181181
"scopes": [
@@ -190,7 +190,7 @@
190190
"name": "Change to strcat_s (Recommended for VC++)",
191191
"type": "regex-replace",
192192
"pattern": {
193-
"pattern": "\\bstrcat\\s*\\(([^,]+),([^,]+)\\)",
193+
"pattern": "\\bstrcat\\s*\\(([^,]+),([^,]+?)\\)",
194194
"type": "regex",
195195
"modifiers": null,
196196
"scopes": [
@@ -204,7 +204,7 @@
204204
"name": "Change to strlcat",
205205
"type": "regex-replace",
206206
"pattern": {
207-
"pattern": "\\bstrcat\\s*\\(([^,]+),([^,]+)\\)",
207+
"pattern": "\\bstrcat\\s*\\(([^,]+),([^,]+?)\\)",
208208
"type": "regex",
209209
"modifiers": null,
210210
"scopes": [
@@ -237,7 +237,7 @@
237237
"rule_info": "DS108330.md",
238238
"patterns": [
239239
{
240-
"pattern": "\\bstrncat\\s*\\(([^,]+),([^,]+),([^,]+)\\)+",
240+
"pattern": "\\bstrncat\\s*\\(([^,]+),([^,]+),([^,]+?)\\)+",
241241
"type": "regex",
242242
"modifiers": null,
243243
"scopes": [
@@ -252,7 +252,7 @@
252252
"name": "Change to strcat_s (Recommended for VC++)",
253253
"type": "regex-replace",
254254
"pattern": {
255-
"pattern": "\\bstrncat\\s*\\(([^,]+),([^,]+),([^,]+)\\)+",
255+
"pattern": "\\bstrncat\\s*\\(([^,]+),([^,]+),([^,]+?)\\)+",
256256
"type": "regex",
257257
"modifiers": null,
258258
"scopes": [
@@ -266,7 +266,7 @@
266266
"name": "Change to strlcat",
267267
"type": "regex-replace",
268268
"pattern": {
269-
"pattern": "\\bstrncat\\s*\\(([^,]+),([^,]+),([^,]+)\\)+",
269+
"pattern": "\\bstrncat\\s*\\(([^,]+),([^,]+),([^,]+?)\\)+",
270270
"type": "regex",
271271
"modifiers": null,
272272
"scopes": [
@@ -872,7 +872,7 @@
872872
},
873873
{
874874
"id": "DS113286",
875-
"name": "Do not include user-input directoy in format strings",
875+
"name": "Do not include user-input directly in format strings",
876876
"overrides": null,
877877
"schema_version": 0,
878878
"tags": [

src/Microsoft.DevSkim/Microsoft.DevSkim.CLI/Writers/SarifWriter.cs

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ public override void WriteIssue(IssueRecord issue)
3333
issue.Issue.Boundary.Length
3434
));
3535
resultItem.Snippet = issue.TextSample;
36-
resultItem.Fixes = GetFixits(issue);
36+
37+
if (issue.Issue.Rule.Fixes != null)
38+
resultItem.Fixes = GetFixits(issue);
3739

3840
resultItem.Locations = new List<CodeAnalysis.Sarif.Location>();
3941
resultItem.Locations.Add(loc);
@@ -47,11 +49,16 @@ public override void FlushAndClose()
4749
sarifLog.Version = SarifVersion.OneZeroZero;
4850
Run runItem = new Run();
4951
runItem.Tool = new Tool();
50-
runItem.Tool.FullName = "Microsoft DevSkim CLI";
51-
runItem.Tool.Name = "DevSkim";
52-
runItem.Tool.Version = Assembly.GetEntryAssembly()
53-
.GetCustomAttribute<AssemblyInformationalVersionAttribute>()
54-
.InformationalVersion;
52+
Assembly entryAssembly = Assembly.GetEntryAssembly();
53+
54+
runItem.Tool.Name = entryAssembly.GetName()
55+
.Name;
56+
57+
runItem.Tool.FullName = entryAssembly.GetCustomAttribute<AssemblyProductAttribute>()
58+
.Product;
59+
60+
runItem.Tool.Version = entryAssembly.GetCustomAttribute<AssemblyInformationalVersionAttribute>()
61+
.InformationalVersion;
5562

5663
runItem.Results = _results;
5764
runItem.Rules = _rules;
@@ -122,6 +129,7 @@ private void AddRuleToSarifRule(Rule devskimRule)
122129
if (!_rules.ContainsKey(devskimRule.Id))
123130
{
124131
CodeAnalysis.Sarif.Rule sarifRule = new CodeAnalysis.Sarif.Rule();
132+
sarifRule.Id = devskimRule.Id;
125133
sarifRule.Name = devskimRule.Name;
126134
sarifRule.FullDescription = devskimRule.Description;
127135
sarifRule.HelpUri = new Uri("https://github.com/Microsoft/DevSkim/blob/master/guidance/" + devskimRule.RuleInfo);

0 commit comments

Comments
 (0)