Skip to content

Commit 085e0f6

Browse files
authored
Merge pull request #150 from GoASTScanner/experimental
Use explicit packages in call lists
2 parents 9a2bec1 + aecbc87 commit 085e0f6

File tree

7 files changed

+19
-15
lines changed

7 files changed

+19
-15
lines changed

call_list.go

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,18 @@ func (c CallList) ContainsCallExpr(n ast.Node, ctx *Context) *ast.CallExpr {
6161
return nil
6262
}
6363

64-
// Try direct resolution
65-
if c.Contains(selector, ident) {
66-
return n.(*ast.CallExpr)
67-
}
68-
69-
// Also support explicit path
64+
// Use only explicit path to reduce conflicts
7065
if path, ok := GetImportPath(selector, ctx); ok && c.Contains(path, ident) {
7166
return n.(*ast.CallExpr)
7267
}
68+
69+
/*
70+
// Try direct resolution
71+
if c.Contains(selector, ident) {
72+
log.Printf("c.Contains == true, %s, %s.", selector, ident)
73+
return n.(*ast.CallExpr)
74+
}
75+
*/
76+
7377
return nil
7478
}

call_list_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ var _ = Describe("call list", func() {
6666
ctx := pkg.CreateContext("md5.go")
6767

6868
// Search for md5.New()
69-
calls.Add("md5", "New")
69+
calls.Add("crypto/md5", "New")
7070

7171
// Stub out visitor and count number of matched call expr
7272
matched := 0

rules/bind.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ func (r *bindsToAllNetworkInterfaces) Match(n ast.Node, c *gas.Context) (*gas.Is
4646
func NewBindsToAllNetworkInterfaces(conf gas.Config) (gas.Rule, []ast.Node) {
4747
calls := gas.NewCallList()
4848
calls.Add("net", "Listen")
49-
calls.Add("tls", "Listen")
49+
calls.Add("crypto/tls", "Listen")
5050
return &bindsToAllNetworkInterfaces{
5151
calls: calls,
5252
pattern: regexp.MustCompile(`^(0.0.0.0|:).*$`),

rules/rsa.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ func (w *weakKeyStrength) Match(n ast.Node, c *gas.Context) (*gas.Issue, error)
3939
// NewWeakKeyStrength builds a rule that detects RSA keys < 2048 bits
4040
func NewWeakKeyStrength(conf gas.Config) (gas.Rule, []ast.Node) {
4141
calls := gas.NewCallList()
42-
calls.Add("rsa", "GenerateKey")
42+
calls.Add("crypto/rsa", "GenerateKey")
4343
bits := 2048
4444
return &weakKeyStrength{
4545
calls: calls,

rules/subproc.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ func (r *subprocess) Match(n ast.Node, c *gas.Context) (*gas.Issue, error) {
5252
// NewSubproc detects cases where we are forking out to an external process
5353
func NewSubproc(conf gas.Config) (gas.Rule, []ast.Node) {
5454
rule := &subprocess{gas.NewCallList()}
55-
rule.Add("exec", "Command")
55+
rule.Add("os/exec", "Command")
5656
rule.Add("syscall", "Exec")
5757
return rule, []ast.Node{(*ast.CallExpr)(nil)}
5858
}

rules/tempfiles.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ func (t *badTempFile) Match(n ast.Node, c *gas.Context) (gi *gas.Issue, err erro
3939
// NewBadTempFile detects direct writes to predictable path in temporary directory
4040
func NewBadTempFile(conf gas.Config) (gas.Rule, []ast.Node) {
4141
calls := gas.NewCallList()
42-
calls.Add("ioutil", "WriteFile")
42+
calls.Add("io/ioutil", "WriteFile")
4343
calls.Add("os", "Create")
4444
return &badTempFile{
4545
calls: calls,

rules/templates.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,10 @@ func (t *templateCheck) Match(n ast.Node, c *gas.Context) (*gas.Issue, error) {
4141
func NewTemplateCheck(conf gas.Config) (gas.Rule, []ast.Node) {
4242

4343
calls := gas.NewCallList()
44-
calls.Add("template", "HTML")
45-
calls.Add("template", "HTMLAttr")
46-
calls.Add("template", "JS")
47-
calls.Add("template", "URL")
44+
calls.Add("html/template", "HTML")
45+
calls.Add("html/template", "HTMLAttr")
46+
calls.Add("html/template", "JS")
47+
calls.Add("html/template", "URL")
4848
return &templateCheck{
4949
calls: calls,
5050
MetaData: gas.MetaData{

0 commit comments

Comments
 (0)