Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ jobs:
strategy:
matrix:
version:
- go-version: "1.24.10"
- go-version: "1.24.11"
golangci: "latest"
- go-version: "1.25.4"
- go-version: "1.25.5"
golangci: "latest"
runs-on: ubuntu-latest
env:
Expand Down Expand Up @@ -52,7 +52,7 @@ jobs:
- name: Setup go
uses: actions/setup-go@v6
with:
go-version: "1.25.4"
go-version: "1.25.5"
- name: Checkout Source
uses: actions/checkout@v6
- uses: actions/cache@v4
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v6
with:
go-version: "1.25.4"
go-version: "1.25.5"
- name: Install Cosign
uses: sigstore/cosign-installer@v3
with:
Expand Down
74 changes: 52 additions & 22 deletions analyzer.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ import (

"golang.org/x/tools/go/analysis"
"golang.org/x/tools/go/analysis/passes/buildssa"
"golang.org/x/tools/go/analysis/passes/ctrlflow"
"golang.org/x/tools/go/analysis/passes/inspect"
"golang.org/x/tools/go/packages"

"github.com/securego/gosec/v2/analyzers"
Expand Down Expand Up @@ -430,7 +432,7 @@ func (gosec *Analyzer) CheckAnalyzers(pkg *packages.Package) {
buildssa.Analyzer: &analyzers.SSAAnalyzerResult{
Config: gosec.Config(),
Logger: gosec.logger,
SSA: ssaResult.(*buildssa.SSA),
SSA: ssaResult,
},
}

Expand Down Expand Up @@ -491,7 +493,7 @@ func (gosec *Analyzer) generatedFiles(pkg *packages.Package) map[string]bool {
}

// buildSSA runs the SSA pass which builds the SSA representation of the package. It handles gracefully any panic.
func (gosec *Analyzer) buildSSA(pkg *packages.Package) (interface{}, error) {
func (gosec *Analyzer) buildSSA(pkg *packages.Package) (*buildssa.SSA, error) {
defer func() {
if r := recover(); r != nil {
gosec.logger.Printf(
Expand All @@ -500,26 +502,54 @@ func (gosec *Analyzer) buildSSA(pkg *packages.Package) (interface{}, error) {
)
}
}()
ssaPass := &analysis.Pass{
Analyzer: buildssa.Analyzer,
Fset: pkg.Fset,
Files: pkg.Syntax,
OtherFiles: pkg.OtherFiles,
IgnoredFiles: pkg.IgnoredFiles,
Pkg: pkg.Types,
TypesInfo: pkg.TypesInfo,
TypesSizes: pkg.TypesSizes,
ResultOf: nil,
Report: nil,
ImportObjectFact: nil,
ExportObjectFact: nil,
ImportPackageFact: nil,
ExportPackageFact: nil,
AllObjectFacts: nil,
AllPackageFacts: nil,
}

return ssaPass.Analyzer.Run(ssaPass)
if pkg == nil {
return nil, errors.New("nil package provided")
}
if pkg.Types == nil {
return nil, fmt.Errorf("package %s has no type information (compilation failed?)", pkg.Name)
}
if pkg.TypesInfo == nil {
return nil, fmt.Errorf("package %s has no type information", pkg.Name)
}
pass := &analysis.Pass{
Fset: pkg.Fset,
Files: pkg.Syntax,
OtherFiles: pkg.OtherFiles,
IgnoredFiles: pkg.IgnoredFiles,
Pkg: pkg.Types,
TypesInfo: pkg.TypesInfo,
TypesSizes: pkg.TypesSizes,
ResultOf: make(map[*analysis.Analyzer]interface{}),
Report: func(d analysis.Diagnostic) {},
ImportObjectFact: func(obj types.Object, fact analysis.Fact) bool { return false },
ExportObjectFact: func(obj types.Object, fact analysis.Fact) {},
}

pass.Analyzer = inspect.Analyzer
i, err := inspect.Analyzer.Run(pass)
if err != nil {
return nil, fmt.Errorf("running inspect analysis: %w", err)
}
pass.ResultOf[inspect.Analyzer] = i

pass.Analyzer = ctrlflow.Analyzer
cf, err := ctrlflow.Analyzer.Run(pass)
if err != nil {
return nil, fmt.Errorf("running control flow analysis: %w", err)
}
pass.ResultOf[ctrlflow.Analyzer] = cf

pass.Analyzer = buildssa.Analyzer
result, err := buildssa.Analyzer.Run(pass)
if err != nil {
return nil, fmt.Errorf("running SSA analysis: %w", err)
}

ssaResult, ok := result.(*buildssa.SSA)
if !ok {
return nil, fmt.Errorf("unexpected SSA analysis result type: %T", result)
}
return ssaResult, nil
}

// ParseErrors parses the errors from given package
Expand Down
Loading