mirror of
https://github.com/securego/gosec.git
synced 2024-12-26 12:35:52 +00:00
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:
parent
edb362fc9d
commit
c6183b4d5c
1 changed files with 9 additions and 6 deletions
15
rules/tls.go
15
rules/tls.go
|
@ -108,12 +108,15 @@ 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 {
|
||||||
for _, elt := range complit.Elts {
|
actualType := c.Info.TypeOf(complit.Type)
|
||||||
if kve, ok := elt.(*ast.KeyValueExpr); ok {
|
if actualType != nil && actualType.String() == t.requiredType {
|
||||||
issue := t.processTLSConfVal(kve, c)
|
for _, elt := range complit.Elts {
|
||||||
if issue != nil {
|
if kve, ok := elt.(*ast.KeyValueExpr); ok {
|
||||||
return issue, nil
|
issue := t.processTLSConfVal(kve, c)
|
||||||
|
if issue != nil {
|
||||||
|
return issue, nil
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue