Skip to content

Commit 81e8278

Browse files
ccojocarCosmin Cojocar
authored andcommitted
Add the Cgo files to the analysed files and ingonre all non-Go files
Signed-off-by: Cosmin Cojocar <[email protected]>
1 parent a1969e2 commit 81e8278

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

analyzer.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
"log"
2525
"os"
2626
"path"
27+
"path/filepath"
2728
"reflect"
2829
"regexp"
2930
"strconv"
@@ -174,6 +175,9 @@ func (gosec *Analyzer) load(pkgPath string, conf *packages.Config) ([]*packages.
174175
for _, filename := range basePackage.GoFiles {
175176
packageFiles = append(packageFiles, path.Join(pkgPath, filename))
176177
}
178+
for _, filename := range basePackage.CgoFiles {
179+
packageFiles = append(packageFiles, path.Join(pkgPath, filename))
180+
}
177181

178182
if gosec.tests {
179183
testsFiles := []string{}
@@ -195,7 +199,13 @@ func (gosec *Analyzer) load(pkgPath string, conf *packages.Config) ([]*packages.
195199
func (gosec *Analyzer) Check(pkg *packages.Package) {
196200
gosec.logger.Println("Checking package:", pkg.Name)
197201
for _, file := range pkg.Syntax {
198-
gosec.logger.Println("Checking file:", pkg.Fset.File(file.Pos()).Name())
202+
checkedFile := pkg.Fset.File(file.Pos()).Name()
203+
// Skip the no-Go file from analysis (e.g. a Cgo files is expanded in 3 different files
204+
// stored in the cache which do not need to by analyzed)
205+
if filepath.Ext(checkedFile) != ".go" {
206+
continue
207+
}
208+
gosec.logger.Println("Checking file:", checkedFile)
199209
gosec.context.FileSet = pkg.Fset
200210
gosec.context.Config = gosec.config
201211
gosec.context.Comments = ast.NewCommentMap(gosec.context.FileSet, file, file.Comments)

0 commit comments

Comments
 (0)