From b4c746962f33c83ec64ce337e546bd0cc6529cd1 Mon Sep 17 00:00:00 2001 From: Dimitar Banchev Date: Fri, 30 Aug 2024 11:50:08 +0200 Subject: [PATCH] Formatting problems(CI was not passing) --- analyzer_test.go | 1 - analyzers/hardcodedNonce.go | 6 ++--- testutils/g407_samples.go | 51 +++++++++++++++++-------------------- 3 files changed, 26 insertions(+), 32 deletions(-) diff --git a/analyzer_test.go b/analyzer_test.go index 2e5591b..f70b5fc 100644 --- a/analyzer_test.go +++ b/analyzer_test.go @@ -1521,7 +1521,6 @@ var _ = Describe("Analyzer", func() { Expect(controlIssues[0].Suppressions[0].Justification).To(Equal("Globally suppressed.")) }) - It("should not report an error if the analyzer is excluded", func() { sample := testutils.SampleCodeG407[0] source := sample.Code[0] diff --git a/analyzers/hardcodedNonce.go b/analyzers/hardcodedNonce.go index 5598c33..875918c 100644 --- a/analyzers/hardcodedNonce.go +++ b/analyzers/hardcodedNonce.go @@ -57,8 +57,8 @@ func runHardCodedNonce(pass *analysis.Pass) (interface{}, error) { "crypto/cipher.NewOFB": {2, 1}, } var issues []*issue.Issue - var ssaPkgFunctions = ssaResult.SSA.SrcFuncs - var savedArgsFromFunctions = *iterateAndGetArgsFromTrackedFunctions(ssaPkgFunctions, &calls) + ssaPkgFunctions := ssaResult.SSA.SrcFuncs + savedArgsFromFunctions := *iterateAndGetArgsFromTrackedFunctions(ssaPkgFunctions, &calls) for _, savedArg := range savedArgsFromFunctions { tmp, err := raiseIssue(savedArg, &calls, ssaPkgFunctions, pass, "") @@ -148,14 +148,12 @@ func raiseIssue(val *ssa.Value, funcsToTrack *map[string][]int, ssaFuncs []*ssa. // Iterate through all places that use the `variable` argument and check if it's used in one of the tracked functions func iterateThroughReferrers(variable *ssa.Value, funcsToTrack *map[string][]int, analyzerID string, issueDescription string, fileSet *token.FileSet, issueSeverity issue.Score, issueConfidence issue.Score) ([]*issue.Issue, error) { - if funcsToTrack == nil || variable == nil || analyzerID == "" || issueDescription == "" || fileSet == nil { return nil, errors.New("received a nil object") } var gosecIssues []*issue.Issue = nil // Go trough all functions that use the given arg variable for _, referrer := range *(*variable).Referrers() { - // Iterate trough the functions we are interested for trackedFunc := range *funcsToTrack { diff --git a/testutils/g407_samples.go b/testutils/g407_samples.go index 3d1b153..85054bb 100644 --- a/testutils/g407_samples.go +++ b/testutils/g407_samples.go @@ -2,11 +2,9 @@ package testutils import "github.com/securego/gosec/v2" -var ( - // SampleCodeG407 - Use of hardcoded nonce/IV - SampleCodeG407 = []CodeSample{ - - {[]string{`package main +// SampleCodeG407 - Use of hardcoded nonce/IV +var SampleCodeG407 = []CodeSample{ + {[]string{`package main import ( "crypto/aes" @@ -25,7 +23,7 @@ func main() { } `}, 1, gosec.NewConfig()}, - {[]string{`package main + {[]string{`package main import ( "crypto/aes" @@ -45,7 +43,7 @@ func main() { `}, 0, gosec.NewConfig()}, - {[]string{`package main + {[]string{`package main import ( "crypto/aes" @@ -79,7 +77,7 @@ func main() { } `}, 0, gosec.NewConfig()}, - {[]string{`package main + {[]string{`package main import ( "crypto/aes" @@ -97,7 +95,7 @@ func main() { }`}, 1, gosec.NewConfig()}, - {[]string{`package main + {[]string{`package main import ( "crypto/aes" @@ -115,7 +113,7 @@ func main() { }`}, 1, gosec.NewConfig()}, - {[]string{`package main + {[]string{`package main import ( "crypto/aes" @@ -134,7 +132,7 @@ func main() { } `}, 1, gosec.NewConfig()}, - {[]string{`package main + {[]string{`package main import ( "crypto/aes" @@ -154,7 +152,7 @@ func main() { } `}, 2, gosec.NewConfig()}, - {[]string{`package main + {[]string{`package main import ( "crypto/aes" @@ -174,7 +172,7 @@ func main() { } `}, 2, gosec.NewConfig()}, - {[]string{`package main + {[]string{`package main import ( "crypto/aes" @@ -195,7 +193,7 @@ func main() { } `}, 2, gosec.NewConfig()}, - {[]string{`package main + {[]string{`package main import ( "crypto/aes" @@ -229,7 +227,7 @@ func main() { } `}, 2, gosec.NewConfig()}, - {[]string{`package main + {[]string{`package main import ( "crypto/aes" @@ -262,7 +260,7 @@ func main() { } `}, 2, gosec.NewConfig()}, - {[]string{`package main + {[]string{`package main import ( "crypto/aes" @@ -282,7 +280,7 @@ func main() { } `}, 2, gosec.NewConfig()}, - {[]string{`package main + {[]string{`package main import ( "crypto/aes" @@ -302,7 +300,7 @@ func main() { } `}, 2, gosec.NewConfig()}, - {[]string{`package main + {[]string{`package main import ( "crypto/aes" @@ -323,7 +321,7 @@ func main() { }`}, 2, gosec.NewConfig()}, - {[]string{`package main + {[]string{`package main import ( "crypto/aes" @@ -344,7 +342,7 @@ func main() { }`}, 2, gosec.NewConfig()}, - {[]string{`package main + {[]string{`package main import ( "crypto/aes" @@ -367,7 +365,7 @@ func main() { }`}, 2, gosec.NewConfig()}, - {[]string{`package main + {[]string{`package main import ( "crypto/aes" @@ -391,7 +389,7 @@ func main() { } `}, 2, gosec.NewConfig()}, - {[]string{`package main + {[]string{`package main import ( "crypto/aes" @@ -408,7 +406,7 @@ func main() { } `}, 1, gosec.NewConfig()}, - {[]string{`package main + {[]string{`package main import ( "crypto/aes" @@ -427,7 +425,7 @@ func main() { } `}, 1, gosec.NewConfig()}, - {[]string{`package main + {[]string{`package main import ( "crypto/aes" @@ -453,7 +451,7 @@ func main() { } `}, 0, gosec.NewConfig()}, - {[]string{`package main + {[]string{`package main import ( "crypto/aes" @@ -472,5 +470,4 @@ func main() { } `}, 1, gosec.NewConfig()}, - } -) +}