@@ -24,6 +24,7 @@ import (
24
24
"log"
25
25
"os"
26
26
"path"
27
+ "path/filepath"
27
28
"reflect"
28
29
"regexp"
29
30
"strconv"
@@ -174,6 +175,9 @@ func (gosec *Analyzer) load(pkgPath string, conf *packages.Config) ([]*packages.
174
175
for _ , filename := range basePackage .GoFiles {
175
176
packageFiles = append (packageFiles , path .Join (pkgPath , filename ))
176
177
}
178
+ for _ , filename := range basePackage .CgoFiles {
179
+ packageFiles = append (packageFiles , path .Join (pkgPath , filename ))
180
+ }
177
181
178
182
if gosec .tests {
179
183
testsFiles := []string {}
@@ -195,7 +199,13 @@ func (gosec *Analyzer) load(pkgPath string, conf *packages.Config) ([]*packages.
195
199
func (gosec * Analyzer ) Check (pkg * packages.Package ) {
196
200
gosec .logger .Println ("Checking package:" , pkg .Name )
197
201
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 )
199
209
gosec .context .FileSet = pkg .Fset
200
210
gosec .context .Config = gosec .config
201
211
gosec .context .Comments = ast .NewCommentMap (gosec .context .FileSet , file , file .Comments )
0 commit comments