mirror of
https://github.com/securego/gosec.git
synced 2025-11-23 22:15:04 +02:00
Fix data race in the analyzer
Signed-off-by: Cosmin Cojocar <gcojocar@adobe.com>
This commit is contained in:
committed by
Cosmin Cojocar
parent
c06903addd
commit
a2397580b6
@@ -184,6 +184,7 @@ type Analyzer struct {
|
||||
trackSuppressions bool
|
||||
concurrency int
|
||||
analyzerList []*analysis.Analyzer
|
||||
mu sync.Mutex
|
||||
}
|
||||
|
||||
// NewAnalyzer builds a new analyzer.
|
||||
@@ -324,7 +325,9 @@ func (gosec *Analyzer) load(pkgPath string, conf *packages.Config) ([]*packages.
|
||||
// step 1/3 create build context.
|
||||
buildD := build.Default
|
||||
// step 2/3: add build tags to get env dependent files into basePackage.
|
||||
gosec.mu.Lock()
|
||||
buildD.BuildTags = conf.BuildFlags
|
||||
gosec.mu.Unlock()
|
||||
basePackage, err := buildD.ImportDir(pkgPath, build.ImportComment)
|
||||
if err != nil {
|
||||
return []*packages.Package{}, fmt.Errorf("importing dir %q: %w", pkgPath, err)
|
||||
@@ -348,7 +351,9 @@ func (gosec *Analyzer) load(pkgPath string, conf *packages.Config) ([]*packages.
|
||||
}
|
||||
|
||||
// step 3/3 remove build tags from conf to proceed build correctly.
|
||||
gosec.mu.Lock()
|
||||
conf.BuildFlags = nil
|
||||
defer gosec.mu.Unlock()
|
||||
pkgs, err := packages.Load(conf, packageFiles...)
|
||||
if err != nil {
|
||||
return []*packages.Package{}, fmt.Errorf("loading files from package %q: %w", pkgPath, err)
|
||||
|
||||
Reference in New Issue
Block a user