Skip to content

Commit

Permalink
SA1029: avoid colissions within context
Browse files Browse the repository at this point in the history
Signed-off-by: Rumen Vasilev <[email protected]>
  • Loading branch information
rumenvasilev committed Nov 11, 2023
1 parent 9ffc266 commit e0184c7
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
12 changes: 8 additions & 4 deletions internal/core/analysis.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ import (
"gopkg.in/src-d/go-git.v4/plumbing/object"
)

type threadID int

const TID threadID = 0

// AnalyzeRepositories will clone the repos, grab their history for analysis of files and content.
//
// Before the analysis is done we also check various conditions that can be thought of as filters and
Expand Down Expand Up @@ -72,7 +76,7 @@ func AnalyzeRepositories(ctx context.Context, sess *session.Session, st *stats.S

func analyzeWorker(ctx context.Context, workerID int, wg *sync.WaitGroup, ch chan coreapi.Repository, sess *session.Session, st *stats.Stats) {
log := log.Log
ctxworker := context.WithValue(ctx, "tid", workerID)
ctxworker := context.WithValue(ctx, TID, workerID)
for {
select {
case <-ctx.Done():
Expand Down Expand Up @@ -114,7 +118,7 @@ func cleanUpPath(path string) {
func analyzeHistory(ctx context.Context, sess *session.Session, clone *_git.Repository, path string, repo coreapi.Repository) {
stats := sess.State.Stats
log := log.Log
tid := ctx.Value("tid")
tid := ctx.Value(TID)
// Get the full commit history for the repo
history, err := git.GetRepositoryHistory(clone)
if err != nil {
Expand Down Expand Up @@ -154,7 +158,7 @@ func analyzeHistory(ctx context.Context, sess *session.Session, clone *_git.Repo
func isDirtyCommit(ctx context.Context, sess *session.Session, commit *object.Commit, repo coreapi.Repository, clone *_git.Repository, path string) bool {
// stats := sess.State.Stats
log := log.Log
tid := ctx.Value("tid")
tid := ctx.Value(TID)
// This will be used to increment the dirty commit stat if any matches are found. A dirty commit
// means that a secret was found in that commit. This provides an easier way to manually to look
// through the commit history of a given repo.
Expand All @@ -173,7 +177,7 @@ func isDirtyCommit(ctx context.Context, sess *session.Session, commit *object.Co

func AnalyzeObject(ctx context.Context, sess *session.Session, change *object.Change, commit *object.Commit, filepath string, repo coreapi.Repository) bool {
log := log.Log
tid := ctx.Value("tid")
tid := ctx.Value(TID)
cfg := sess.Config
fPath := filepath

Expand Down
2 changes: 1 addition & 1 deletion internal/pkg/scan/localpath/localpath.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func (l Localpath) Run() error {
// By default we display a header to the user giving basic info about application. This will not be displayed
// during a silent run which is the default when using this in an automated fashion.
banner.HeaderInfo(cfg.Global, sess.State.Stats.StartedAt.Format(time.RFC3339), len(sess.Signatures))
ctxworker := context.WithValue(ctx, "tid", 0)
ctxworker := context.WithValue(ctx, core.TID, 0)
for _, p := range cfg.Local.Paths {
if util.PathExists(p) {
last := p[len(p)-1:]
Expand Down

0 comments on commit e0184c7

Please sign in to comment.