Skip to content

Commit

Permalink
Added \s* to catch spaces between API and ()
Browse files Browse the repository at this point in the history
we were missing scenarios like gets (str) because of the space.  Adding
\s* will catch that
  • Loading branch information
joshbw committed Mar 13, 2017
1 parent 72864ce commit 8fdf0ad
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 19 deletions.
30 changes: 15 additions & 15 deletions rules/default/security/api/dangerous_api.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"rule_info": "https://github.com/Microsoft/DevSkim/blob/master/guidance/DS185832.md",
"patterns": [
{
"pattern": "\\bstrcpy\\(([^,]+),([^,\\)]+)\\)",
"pattern": "\\bstrcpy\\s*\\(([^,]+),([^,\\)]+)\\)",
"type": "regex",
"subtype": [
"function-call"
Expand All @@ -54,13 +54,13 @@
{
"type": "regex_substitute",
"name": "Change to strcpy_s (Recommended for VC++)",
"search": "\\bstrcpy\\(([^,]+),([^,\\)]+)\\)",
"search": "\\bstrcpy\\s*\\(([^,]+),([^,\\)]+)\\)",
"replace": "strcpy_s($1, <size of $1>, $2)"
},
{
"type": "regex_substitute",
"name": "Change to strlcpy",
"search": "\\bstrcpy\\(([^,]+),([^,\\)]+)\\)",
"search": "\\bstrcpy\\s*\\(([^,]+),([^,\\)]+)\\)",
"replace": "strlcpy($1, $2, <size of $1>)"
}
]
Expand All @@ -83,7 +83,7 @@
"rule_info": "https://github.com/Microsoft/DevSkim/blob/master/guidance/DS111237.md",
"patterns": [
{
"pattern": "\\bstrncpy\\(([^,]+),([^,]+),([^,\\)]+)\\)",
"pattern": "\\bstrncpy\\s*\\(([^,]+),([^,]+),([^,\\)]+)\\)",
"type": "regex",
"subtype": [
"function-call"
Expand All @@ -94,13 +94,13 @@
{
"type": "regex_substitute",
"name": "Change to strcpy_s (Recommended for VC++)",
"search": "\\bstrncpy\\(([^,]+),([^,]+),([^,\\)]+)\\)",
"search": "\\bstrncpy\\s*\\(([^,]+),([^,]+),([^,\\)]+)\\)",
"replace": "strcpy_s($1, $3, $2)"
},
{
"type": "regex_substitute",
"name": "Change to strlcpy",
"search": "\\bstrncpy\\(([^,]+),([^,]+),([^,\\)]+)\\)",
"search": "\\bstrncpy\\s*\\(([^,]+),([^,]+),([^,\\)]+)\\)",
"replace": "strlcpy($1, $2, $3)"
}
]
Expand All @@ -123,7 +123,7 @@
"rule_info": "https://github.com/Microsoft/DevSkim/blob/master/guidance/DS141863.md",
"patterns": [
{
"pattern": "\\bstrcat\\(([^,]+),([^,\\)]+)\\)",
"pattern": "\\bstrcat\\s*\\(([^,]+),([^,\\)]+)\\)",
"type": "regex",
"subtype": [
"function-call"
Expand All @@ -134,13 +134,13 @@
{
"type": "regex_substitute",
"name": "Change to strcat_s (Recommended for VC++)",
"search": "\\bstrcat\\(([^,]+),([^,\\)]+)\\)",
"search": "\\bstrcat\\s*\\(([^,]+),([^,\\)]+)\\)",
"replace": "strcat_s($1, <size of $1>, $2)"
},
{
"type": "regex_substitute",
"name": "Change to strlcat",
"search": "\\bstrcat\\(([^,]+),([^,\\)]+)\\)",
"search": "\\bstrcat\\s*\\(([^,]+),([^,\\)]+)\\)",
"replace": "strlcat($1, $2, <size of $1>)"
}
]
Expand All @@ -163,7 +163,7 @@
"rule_info": "https://github.com/Microsoft/DevSkim/blob/master/guidance/DS108330.md",
"patterns": [
{
"pattern": "\\bstrncat\\(([^,]+),([^,]+),([^,\\)]+)\\)",
"pattern": "\\bstrncat\\s*\\(([^,]+),([^,]+),([^,\\)]+)\\)",
"type": "regex",
"subtype": [
"function-call"
Expand All @@ -174,13 +174,13 @@
{
"type": "regex_substitute",
"name": "Change to strcat_s (Recommended for VC++)",
"search": "\\bstrncat\\(([^,]+),([^,]+),([^,\\)]+)\\)",
"search": "\\bstrncat\\s*\\(([^,]+),([^,]+),([^,\\)]+)\\)",
"replace": "strcat_s($1, $3, $2)"
},
{
"type": "regex_substitute",
"name": "Change to strlcat",
"search": "\\bstrncat\\(([^,]+),([^,]+),([^,\\)]+)\\)",
"search": "\\bstrncat\\s*\\(([^,]+),([^,]+),([^,\\)]+)\\)",
"replace": "strlcat($1, $2, $3)"
}
]
Expand All @@ -203,7 +203,7 @@
"rule_info": "https://github.com/Microsoft/DevSkim/blob/master/guidance/DS181021.md",
"patterns": [
{
"pattern": "\\bgets\\(([^,\\)]+)\\)",
"pattern": "\\bgets\\s*\\(([^,\\)]+)\\)",
"type": "regex",
"subtype": [
"function-call"
Expand All @@ -214,13 +214,13 @@
{
"type": "regex_substitute",
"name": "Change to gets_s (Recommended for VC++)",
"search": "\\bgets\\(([^,\\)]+)\\)",
"search": "\\bgets\\s*\\(([^,\\)]+)\\)",
"replace": "gets_s($1, <size of $1>)"
},
{
"type": "regex_substitute",
"name": "Change to fgets",
"search": "\\bgets\\(([^,\\)]+)\\)",
"search": "\\bgets\\s*\\(([^,\\)]+)\\)",
"replace": "fgets($1, <size of $1>, stdin)"
}
]
Expand Down
8 changes: 4 additions & 4 deletions rules/default/security/api/suggested_api.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@
"rule_info": "https://github.com/Microsoft/DevSkim/blob/master/guidance/DS161085.md",
"patterns": [
{
"pattern": "\\bmalloc\\(([^,\\)]+)\\)",
"pattern": "\\bmalloc\\s*\\(([^,\\)]+)\\)",
"type": "regex"
}
],
"fix_it": [
{
"type": "regex_substitute",
"name": "Change to calloc ",
"search": "\\bmalloc\\(([^,\\)]+)\\)",
"search": "\\bmalloc\\s*\\(([^,\\)]+)\\)",
"replace": "calloc(<number of elements>, <size of each element>)"
}
]
Expand All @@ -48,7 +48,7 @@
"rule_info": "https://github.com/Microsoft/DevSkim/blob/master/guidance/DS121708.md",
"patterns": [
{
"pattern": "\\bmemcpy\\(([^,]+),([^,]+),([^,\\)]+)\\)",
"pattern": "\\bmemcpy\\s*\\(([^,]+),([^,]+),([^,\\)]+)\\)",
"type": "regex",
"subtype": [
"function-call"
Expand All @@ -59,7 +59,7 @@
{
"type": "regex_substitute",
"name": "Change to memcpy_s (Recommended for VC++)",
"search": "\\bmemcpy\\(([^,]+),([^,]+),([^,\\)]+)\\)",
"search": "\\bmemcpy\\s*\\(([^,]+),([^,]+),([^,\\)]+)\\)",
"replace": "memcpy_s($1, <size of $1>, $2, $3)"
}
]
Expand Down

0 comments on commit 8fdf0ad

Please sign in to comment.