Skip to content

Commit

Permalink
Maps aren't safe for concurrent access, fixed with mutex
Browse files Browse the repository at this point in the history
  • Loading branch information
garethr committed May 8, 2023
1 parent a948dda commit 33968f0
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/enrich.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package lib
import (
"encoding/json"
"strconv"
"sync"
"time"

"github.com/snyk/parlay/ecosystems/packages"
Expand Down Expand Up @@ -213,6 +214,7 @@ func EnrichSBOMWithSnyk(bom *cdx.BOM) *cdx.BOM {
}

wg := sizedwaitgroup.New(20)
var mutex = &sync.Mutex{}
vulnerabilities := make(map[cdx.Component][]issues.CommonIssueModelVTwo)
for i, component := range *bom.Components {
wg.Add()
Expand All @@ -225,7 +227,9 @@ func EnrichSBOMWithSnyk(bom *cdx.BOM) *cdx.BOM {
var packageDoc issues.IssuesWithPurlsResponse
if err := json.Unmarshal(packageData, &packageDoc); err == nil {
if packageDoc.Data != nil {
mutex.Lock()
vulnerabilities[component] = *packageDoc.Data
mutex.Unlock()
}
}
}
Expand Down

0 comments on commit 33968f0

Please sign in to comment.