Skip to content

Commit c6183b4

Browse files
authored
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
1 parent edb362f commit c6183b4

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

rules/tls.go

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -108,12 +108,15 @@ func (t *insecureConfigTLS) processTLSConfVal(n *ast.KeyValueExpr, c *gas.Contex
108108
}
109109

110110
func (t *insecureConfigTLS) Match(n ast.Node, c *gas.Context) (*gas.Issue, error) {
111-
if complit, ok := n.(*ast.CompositeLit); ok && complit.Type != nil && c.Info.TypeOf(complit.Type).String() == t.requiredType {
112-
for _, elt := range complit.Elts {
113-
if kve, ok := elt.(*ast.KeyValueExpr); ok {
114-
issue := t.processTLSConfVal(kve, c)
115-
if issue != nil {
116-
return issue, nil
111+
if complit, ok := n.(*ast.CompositeLit); ok && complit.Type != nil {
112+
actualType := c.Info.TypeOf(complit.Type)
113+
if actualType != nil && actualType.String() == t.requiredType {
114+
for _, elt := range complit.Elts {
115+
if kve, ok := elt.(*ast.KeyValueExpr); ok {
116+
issue := t.processTLSConfVal(kve, c)
117+
if issue != nil {
118+
return issue, nil
119+
}
117120
}
118121
}
119122
}

0 commit comments

Comments
 (0)