Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 Fix loop aliasing errors causing linter to fail. #3414

Merged
merged 1 commit into from
Aug 23, 2023
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
14 changes: 12 additions & 2 deletions checks/evaluation/permissions/permissions.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,16 @@ func TokenPermissions(name string, c *checker.CheckRequest, r *checker.TokenPerm
"GitHub workflow tokens follow principle of least privilege")
}

// avoid memory aliasing by returning a new copy.
func newUint(u uint) *uint {
return &u
}

// avoid memory aliasing by returning a new copy.
func newStr(s string) *string {
return &s
}

func applyScorePolicy(results *checker.TokenPermissionsData, c *checker.CheckRequest) (int, error) {
// See list https://github.blog/changelog/2021-04-20-github-actions-control-permissions-for-github_token/.
// Note: there are legitimate reasons to use some of the permissions like checks, deployments, etc.
Expand All @@ -83,10 +93,10 @@ func applyScorePolicy(results *checker.TokenPermissionsData, c *checker.CheckReq
loc = &finding.Location{
Type: r.File.Type,
Path: r.File.Path,
LineStart: &r.File.Offset,
LineStart: newUint(r.File.Offset),
}
if r.File.Snippet != "" {
loc.Snippet = &r.File.Snippet
loc.Snippet = newStr(r.File.Snippet)
}
}

Expand Down
4 changes: 2 additions & 2 deletions clients/git/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func createTestRepo(t *testing.T) (path string) {
return dir
}

//nolint:testparallel
//nolint:paralleltest
func TestInitRepo(t *testing.T) {
tests := []struct { //nolint:govet
name string
Expand Down Expand Up @@ -147,7 +147,7 @@ func TestListCommits(t *testing.T) {
}
}

//nolint:testparallel
//nolint:paralleltest
func TestSearch(t *testing.T) {
testCases := []struct {
name string
Expand Down
4 changes: 0 additions & 4 deletions clients/gitlabrepo/issues_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,6 @@ func (s suffixStubTripper) RoundTrip(r *http.Request) (*http.Response, error) {
}, nil
}

func strptr(s string) *string {
return &s
}

func associationptr(r clients.RepoAssociation) *clients.RepoAssociation {
return &r
}
Expand Down
7 changes: 6 additions & 1 deletion clients/gitlabrepo/workflows.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,19 @@
return workflowsRunsFrom(jobs, filename), nil
}

// avoid memory aliasing by returning a new copy.
func strptr(s string) *string {
return &s
}

func workflowsRunsFrom(data []*gitlab.Job, filename string) []clients.WorkflowRun {
var workflowRuns []clients.WorkflowRun
for _, job := range data {
// Find a better way to do this.
for _, artifact := range job.Artifacts {
if strings.EqualFold(artifact.Filename, filename) {
workflowRuns = append(workflowRuns, clients.WorkflowRun{
HeadSHA: &job.Pipeline.Sha,
HeadSHA: strptr(job.Pipeline.Sha),

Check warning on line 59 in clients/gitlabrepo/workflows.go

View check run for this annotation

Codecov / codecov/patch

clients/gitlabrepo/workflows.go#L59

Added line #L59 was not covered by tests
URL: job.WebURL,
})
continue
Expand Down
6 changes: 3 additions & 3 deletions pkg/json_raw_results.go
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ func (r *jsonScorecardRawResult) addTokenPermissionsRawResults(tp *checker.Token
Offset: t.File.Offset,
}
if t.File.Snippet != "" {
p.File.Snippet = &t.File.Snippet
p.File.Snippet = asPointer(t.File.Snippet)
}
}

Expand Down Expand Up @@ -361,7 +361,7 @@ func (r *jsonScorecardRawResult) addPackagingRawResults(pk *checker.PackagingDat
}

if p.File.Snippet != "" {
jpk.File.Snippet = &p.File.Snippet
jpk.File.Snippet = asPointer(p.File.Snippet)
}

for _, run := range p.Runs {
Expand Down Expand Up @@ -419,7 +419,7 @@ func (r *jsonScorecardRawResult) addDangerousWorkflowRawResults(df *checker.Dang
Type: string(e.Type),
}
if e.File.Snippet != "" {
v.File.Snippet = &e.File.Snippet
v.File.Snippet = asPointer(e.File.Snippet)
}
if e.Job != nil {
v.Job = &jsonWorkflowJob{
Expand Down
Loading