mirror of
https://github.com/securego/gosec.git
synced 2025-07-03 00:27:05 +02:00
Handle nil when looking up a file by position into a package (#747)
This commit is contained in:
@ -219,7 +219,12 @@ func (gosec *Analyzer) load(pkgPath string, conf *packages.Config) ([]*packages.
|
|||||||
func (gosec *Analyzer) Check(pkg *packages.Package) {
|
func (gosec *Analyzer) Check(pkg *packages.Package) {
|
||||||
gosec.logger.Println("Checking package:", pkg.Name)
|
gosec.logger.Println("Checking package:", pkg.Name)
|
||||||
for _, file := range pkg.Syntax {
|
for _, file := range pkg.Syntax {
|
||||||
checkedFile := pkg.Fset.File(file.Pos()).Name()
|
fp := pkg.Fset.File(file.Pos())
|
||||||
|
if fp == nil {
|
||||||
|
// skip files which cannot be located
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
checkedFile := fp.Name()
|
||||||
// Skip the no-Go file from analysis (e.g. a Cgo files is expanded in 3 different files
|
// Skip the no-Go file from analysis (e.g. a Cgo files is expanded in 3 different files
|
||||||
// stored in the cache which do not need to by analyzed)
|
// stored in the cache which do not need to by analyzed)
|
||||||
if filepath.Ext(checkedFile) != ".go" {
|
if filepath.Ext(checkedFile) != ".go" {
|
||||||
|
Reference in New Issue
Block a user