Add nil pointer check to rule. (#181)

TypeOf returns the type of expression e, or nil if not found. We are
calling .String() on a value that may be nil in this clause.

Relates to #174
This commit is contained in:
Grant Murphy 2018-02-28 04:29:25 +10:00 committed by GitHub
parent edb362fc9d
commit c6183b4d5c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -108,7 +108,9 @@ func (t *insecureConfigTLS) processTLSConfVal(n *ast.KeyValueExpr, c *gas.Contex
} }
func (t *insecureConfigTLS) Match(n ast.Node, c *gas.Context) (*gas.Issue, error) { func (t *insecureConfigTLS) Match(n ast.Node, c *gas.Context) (*gas.Issue, error) {
if complit, ok := n.(*ast.CompositeLit); ok && complit.Type != nil && c.Info.TypeOf(complit.Type).String() == t.requiredType { if complit, ok := n.(*ast.CompositeLit); ok && complit.Type != nil {
actualType := c.Info.TypeOf(complit.Type)
if actualType != nil && actualType.String() == t.requiredType {
for _, elt := range complit.Elts { for _, elt := range complit.Elts {
if kve, ok := elt.(*ast.KeyValueExpr); ok { if kve, ok := elt.(*ast.KeyValueExpr); ok {
issue := t.processTLSConfVal(kve, c) issue := t.processTLSConfVal(kve, c)
@ -118,5 +120,6 @@ func (t *insecureConfigTLS) Match(n ast.Node, c *gas.Context) (*gas.Issue, error
} }
} }
} }
}
return nil, nil return nil, nil
} }