Skip to content

Commit

Permalink
fixed rules and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Pavel Bansky committed Jan 17, 2018
1 parent 8dea226 commit 5761651
Show file tree
Hide file tree
Showing 26 changed files with 172 additions and 346 deletions.
10 changes: 10 additions & 0 deletions rules/default/security/api/tests/DS108330.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
line: 5
=====
int main ()
{
char str1[20];
char str2[20];
strncat (str1, str2, 6);

return 0;
}
12 changes: 12 additions & 0 deletions rules/default/security/api/tests/DS111237.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
line: 7
====
int main ()
{
char str1[]= "To be or not to be";
char str2[40];
char str3[40];

strncpy ( str2, str1, sizeof(str2) );

return 0;
}
8 changes: 8 additions & 0 deletions rules/default/security/api/tests/DS141863.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
line: 4
====
int main ()
{
char str[80];
strcat (str,"strings ");
return 0;
}
11 changes: 11 additions & 0 deletions rules/default/security/api/tests/DS154189.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
line: 5
line: 6
=====
int main ()
{
char buffer [50];
int n, a=5, b=3;
n=sprintf (buffer, "%d plus %d is %d", a, b, a+b);
printf ("[%s] is a string %d chars long\n",buffer,n);
return 0;
}
10 changes: 10 additions & 0 deletions rules/default/security/api/tests/DS181021.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
line: 5
=====
int main()
{
char string [256];

gets (string); // warning: unsafe (see fgets instead)

return 0;
}
13 changes: 13 additions & 0 deletions rules/default/security/api/tests/DS185832.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
line: 6
line: 7
=====
int main ()
{
char str1[]="Sample string";
char str2[40];
char str3[40];
strcpy (str2,str1);
strcpy (str3,"copy successful");

return 0;
}
8 changes: 0 additions & 8 deletions rules/default/security/cryptography/certificate.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,6 @@
],
"_comment": ""
},
{
"pattern": "setValidatesSecureCertificate:\\s*NO",
"type": "regex",
"scopes": [
"code"
],
"_comment": ""
},
{
"pattern": "validatesSecureCertificate\\s*=\\s*NO",
"type": "regex",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
line: 3
line: 3 expect DS175862
===============================================
<?php

Expand Down
3 changes: 3 additions & 0 deletions rules/default/security/privacy/tests/DS165348.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
line: 1
=====
uniqueIdentifier
Empty file.
121 changes: 0 additions & 121 deletions rules/default/security/vulnerable_libraries/microsoft_nuget.json
Original file line number Diff line number Diff line change
Expand Up @@ -192,126 +192,5 @@
"_comment": ""
}
]
},
{
"name": "Vulnerable NuGet Library",
"id": "DS300006",
"description": "Vulnerabilities in ASP.NET Core View Components Could Allow Elevation of Privilege",
"recommendation": "Upgrade this package to a later, unaffected version.",
"applies_to": [
"packages.config"
],
"tags": [
"Vulerable-Dependency.Library.NuGet"
],
"severity": "moderate",
"_comment": "",
"rule_info": "3181759",
"patterns": [
{
"pattern": "<package id=\"Microsoft.AspNetCore.Mvc.Abstractions\" version=\"(1\\.0\\.0)\"",
"type": "regex",
"scopes": [
"code"
],
"_comment": ""
},
{
"pattern": "<package id=\"Microsoft.AspNetCore.Mvc.ApiExplorer\" version=\"(1\\.0\\.0)\"",
"type": "regex",
"scopes": [
"code"
],
"_comment": ""
},
{
"pattern": "<package id=\"Microsoft.AspNetCore.Mvc.Core\" version=\"(1\\.0\\.0)\"",
"type": "regex",
"scopes": [
"code"
],
"_comment": ""
},
{
"pattern": "<package id=\"Microsoft.AspNetCore.Mvc.Cors\" version=\"(1\\.0\\.0)\"",
"type": "regex",
"scopes": [
"code"
],
"_comment": ""
},
{
"pattern": "<package id=\"Microsoft.AspNetCore.Mvc.DataAnnotations\" version=\"(1\\.0\\.0)\"",
"type": "regex",
"scopes": [
"code"
],
"_comment": ""
},
{
"pattern": "<package id=\"Microsoft.AspNetCore.Mvc.Formatters.Json\" version=\"(1\\.0\\.0)\"",
"type": "regex",
"scopes": [
"code"
],
"_comment": ""
},
{
"pattern": "<package id=\"Microsoft.AspNetCore.Mvc.Formatters.Xml\" version=\"(1\\.0\\.0)\"",
"type": "regex",
"scopes": [
"code"
],
"_comment": ""
},
{
"pattern": "<package id=\"Microsoft.AspNetCore.Mvc.Localization\" version=\"(1\\.0\\.0)\"",
"type": "regex",
"scopes": [
"code"
],
"_comment": ""
},
{
"pattern": "<package id=\"Microsoft.AspNetCore.Mvc.Razor\" version=\"(1\\.0\\.0)\"",
"type": "regex",
"scopes": [
"code"
],
"_comment": ""
},
{
"pattern": "<package id=\"Microsoft.AspNetCore.Mvc.Razor.Host\" version=\"(1\\.0\\.0)\"",
"type": "regex",
"scopes": [
"code"
],
"_comment": ""
},
{
"pattern": "<package id=\"Microsoft.AspNetCore.Mvc.TagHelpers\" version=\"(1\\.0\\.0)\"",
"type": "regex",
"scopes": [
"code"
],
"_comment": ""
},
{
"pattern": "<package id=\"Microsoft.AspNetCore.Mvc.ViewFeatures\" version=\"(1\\.0\\.0)\"",
"type": "regex",
"scopes": [
"code"
],
"_comment": ""
},
{
"pattern": "<package id=\"Microsoft.AspNetCore.Mvc.WebApiCompatShim\" version=\"(1\\.0\\.0)\"",
"type": "regex",
"scopes": [
"code"
],
"_comment": ""
}
]
}
]
3 changes: 3 additions & 0 deletions rules/default/security/xml/tests/DS132780.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
line: 1
======
shouldResolveExternalEntities=TRUE
3 changes: 3 additions & 0 deletions rules/default/security/xml/tests/DS132790.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
line: 1
=========
setShouldResolveExternalEntities: YES
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,20 @@ public static void Configure(CommandLineApplication command)
var locationArgument = command.Argument("[path]",
"Path to rules");

var coverageOption = command.Option("-c|--coverage",
"Test coverage information",
CommandOptionType.NoValue);

command.OnExecute(() => {
return (new TestCommand(locationArgument.Value)).Run();
return (new TestCommand(locationArgument.Value,
coverageOption.HasValue())).Run();
});
}

public TestCommand(string path)
public TestCommand(string path, bool coverage)
{
_path = path;
_coverage = coverage;
}

public int Run()
Expand All @@ -40,11 +46,11 @@ public int Run()
return (int)ExitCode.IssuesExists;

Tester tester = new Tester(verifier.CompiledRuleset);
tester.Run(_path);

return (int)ExitCode.NoIssues;
tester.DoCoverage = _coverage;
return tester.Run(_path);
}

private string _path;
private bool _coverage;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<ApplicationIcon />
<PackageId>Microsoft.DevSkim.CLI</PackageId>
<Product>Microsoft DevSkim Command Line Interface</Product>
<Version>0.1.7</Version>
<Version>0.1.8</Version>
<Authors>Microsoft</Authors>
<Company>Microsoft</Company>
<Copyright>(c) Microsoft Corporation. All rights reserved</Copyright>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"profiles": {
"Microsoft.DevSkim.CLI": {
"commandName": "Project",
"commandLineArgs": "test d:\\projects\\DevSkim\\rules"
"commandLineArgs": "test d:\\A\\rules -c"
}
}
}
Loading

0 comments on commit 5761651

Please sign in to comment.