-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New Checks: XR007 and XR008: Check for os/exec.Command and os/exec.Co…
- Loading branch information
Showing
29 changed files
with
507 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
passes/stdlib/osexeccommandcallexpr/osexeccommandcallexpr.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package osexeccommandcallexpr | ||
|
||
import ( | ||
"github.com/bflad/tfproviderlint/helper/analysisutils" | ||
) | ||
|
||
var Analyzer = analysisutils.StdlibFunctionCallExprAnalyzer( | ||
"osexeccommandcallexpr", | ||
"os/exec", | ||
"Command", | ||
) |
15 changes: 15 additions & 0 deletions
15
passes/stdlib/osexeccommandcallexpr/osexeccommandcallexpr_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package osexeccommandcallexpr | ||
|
||
import ( | ||
"testing" | ||
|
||
"golang.org/x/tools/go/analysis" | ||
) | ||
|
||
func TestValidateAnalyzer(t *testing.T) { | ||
err := analysis.Validate([]*analysis.Analyzer{Analyzer}) | ||
|
||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
passes/stdlib/osexeccommandcontextcallexpr/osexeccommandcontextcallexpr.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package osexeccommandcontextcallexpr | ||
|
||
import ( | ||
"github.com/bflad/tfproviderlint/helper/analysisutils" | ||
) | ||
|
||
var Analyzer = analysisutils.StdlibFunctionCallExprAnalyzer( | ||
"osexeccommandcontextcallexpr", | ||
"os/exec", | ||
"CommandContext", | ||
) |
15 changes: 15 additions & 0 deletions
15
passes/stdlib/osexeccommandcontextcallexpr/osexeccommandcontextcallexpr_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package osexeccommandcontextcallexpr | ||
|
||
import ( | ||
"testing" | ||
|
||
"golang.org/x/tools/go/analysis" | ||
) | ||
|
||
func TestValidateAnalyzer(t *testing.T) { | ||
err := analysis.Validate([]*analysis.Analyzer{Analyzer}) | ||
|
||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
passes/stdlib/osexeccommandcontextselectorexpr/osexeccommandcontextselectorexpr.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package osexeccommandcontextselectorexpr | ||
|
||
import ( | ||
"github.com/bflad/tfproviderlint/helper/analysisutils" | ||
) | ||
|
||
var Analyzer = analysisutils.StdlibFunctionSelectorExprAnalyzer( | ||
"osexeccommandselectorexpr", | ||
"os/exec", | ||
"CommandContext", | ||
) |
15 changes: 15 additions & 0 deletions
15
passes/stdlib/osexeccommandcontextselectorexpr/osexeccommandcontextselectorexpr_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package osexeccommandcontextselectorexpr | ||
|
||
import ( | ||
"testing" | ||
|
||
"golang.org/x/tools/go/analysis" | ||
) | ||
|
||
func TestValidateAnalyzer(t *testing.T) { | ||
err := analysis.Validate([]*analysis.Analyzer{Analyzer}) | ||
|
||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
passes/stdlib/osexeccommandselectorexpr/osexeccommandselectorexpr.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package osexeccommandselectorexpr | ||
|
||
import ( | ||
"github.com/bflad/tfproviderlint/helper/analysisutils" | ||
) | ||
|
||
var Analyzer = analysisutils.StdlibFunctionSelectorExprAnalyzer( | ||
"osexeccommandselectorexpr", | ||
"os/exec", | ||
"Command", | ||
) |
15 changes: 15 additions & 0 deletions
15
passes/stdlib/osexeccommandselectorexpr/osexeccommandselectorexpr_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package osexeccommandselectorexpr | ||
|
||
import ( | ||
"testing" | ||
|
||
"golang.org/x/tools/go/analysis" | ||
) | ||
|
||
func TestValidateAnalyzer(t *testing.T) { | ||
err := analysis.Validate([]*analysis.Analyzer{Analyzer}) | ||
|
||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# XR007 | ||
|
||
The XR007 analyzer reports usage of the [`os/exec.Command()`](https://pkg.go.dev/os/exec#Command) function. Providers that are using Go language based SDKs likely want to prevent any execution of other binaries for various reasons such as security and unexpected requirements (e.g. tool installation outside Terraform). | ||
|
||
## Flagged Code | ||
|
||
```go | ||
var sneaky = exec.Command | ||
|
||
sneaky("evilprogram") | ||
|
||
exec.Command("evilprogram") | ||
``` | ||
|
||
## Passing Code | ||
|
||
```go | ||
// Not present :) | ||
``` | ||
|
||
## Ignoring Reports | ||
|
||
Singular reports can be ignored by adding the a `//lintignore:XR007` Go code comment at the end of the offending line or on the line immediately proceding, e.g. | ||
|
||
```go | ||
//lintignore:XR007 | ||
exec.Command("evilprogram") | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package XR007 | ||
|
||
import ( | ||
"github.com/bflad/tfproviderlint/helper/analysisutils" | ||
"github.com/bflad/tfproviderlint/passes/stdlib/osexeccommandcallexpr" | ||
"github.com/bflad/tfproviderlint/passes/stdlib/osexeccommandselectorexpr" | ||
) | ||
|
||
var Analyzer = analysisutils.AvoidSelectorExprAnalyzer( | ||
"XR007", | ||
osexeccommandcallexpr.Analyzer, | ||
osexeccommandselectorexpr.Analyzer, | ||
"os/exec", | ||
"Command", | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package XR007_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/bflad/tfproviderlint/xpasses/XR007" | ||
"golang.org/x/tools/go/analysis/analysistest" | ||
) | ||
|
||
func TestXR007(t *testing.T) { | ||
testdata := analysistest.TestData() | ||
analysistest.Run(t, testdata, XR007.Analyzer, "a") | ||
} | ||
|
||
func TestAnalyzerFixes(t *testing.T) { | ||
testdata := analysistest.TestData() | ||
analysistest.RunWithSuggestedFixes(t, testdata, XR007.Analyzer, "a") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package a | ||
|
||
import ( | ||
e "os/exec" | ||
) | ||
|
||
var failingAlias = e.Command // want "avoid os/exec.Command" | ||
|
||
func fAlias() { | ||
e.Command("true") // want "avoid os/exec.Command" | ||
|
||
failingAlias("true") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package a | ||
|
||
import ( | ||
e "os/exec" | ||
) | ||
|
||
// want "avoid os/exec.Command" | ||
|
||
func fAlias() { | ||
// want "avoid os/exec.Command" | ||
|
||
failingAlias("true") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package a | ||
|
||
import ( | ||
"os/exec" | ||
) | ||
|
||
var failing = exec.Command // want "avoid os/exec.Command" | ||
|
||
func f() { | ||
// Comment ignored | ||
|
||
//lintignore:XR007 | ||
exec.Command("true") | ||
|
||
exec.Command("true") //lintignore:XR007 | ||
|
||
// Failing | ||
|
||
exec.Command("true") // want "avoid os/exec.Command" | ||
|
||
failing("true") | ||
} |
Oops, something went wrong.