Fix multifile ignores

This commit is contained in:
Alex Gartner 2024-07-11 12:08:11 -07:00 committed by Cosmin Cojocar
parent 2f1b81b889
commit 007626773c
2 changed files with 39 additions and 1 deletions

View file

@ -390,7 +390,6 @@ func (gosec *Analyzer) CheckRules(pkg *packages.Package) {
gosec.context.PkgFiles = pkg.Syntax gosec.context.PkgFiles = pkg.Syntax
gosec.context.Imports = NewImportTracker() gosec.context.Imports = NewImportTracker()
gosec.context.PassedValues = make(map[string]interface{}) gosec.context.PassedValues = make(map[string]interface{})
gosec.context.Ignores = newIgnores()
gosec.updateIgnores() gosec.updateIgnores()
ast.Walk(gosec, file) ast.Walk(gosec, file)
gosec.stats.NumFiles++ gosec.stats.NumFiles++

View file

@ -115,4 +115,43 @@ func main() {
fmt.Println(b) fmt.Println(b)
} }
`}, 1, gosec.NewConfig()}, `}, 1, gosec.NewConfig()},
{[]string{
`
package main
import (
"fmt"
"math"
)
func main() {
var a uint = math.MaxUint
// #nosec G115
b := int64(a)
fmt.Println(b)
}
`,
}, 0, gosec.NewConfig()},
{[]string{
`
package main
import (
"fmt"
"math"
)
func main() {
var a uint = math.MaxUint
// #nosec G115
b := int64(a)
fmt.Println(b)
}
`, `
package main
func ExampleFunction() {
}
`,
}, 0, gosec.NewConfig()},
} }