Skip to content

Commit

Permalink
fix: concurrency protection for bom library data struct (#66)
Browse files Browse the repository at this point in the history
Signed-off-by: Ramkumar Chinchani <[email protected]>
  • Loading branch information
rchincha authored Feb 27, 2024
1 parent 9db7ed8 commit 9a3eb8f
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion pkg/fs/verify.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"runtime"
"strconv"
"strings"
"sync"
"sync/atomic"

"github.com/rs/zerolog/log"
Expand Down Expand Up @@ -95,6 +96,8 @@ func Verify(input, inventory, missing string) error {
mdoc := bom.NewDocument("", "")
mdoc.Name = "missing-files-document"

var mdocMtx sync.Mutex

var mcount atomic.Uint64

backlog := 1024
Expand Down Expand Up @@ -128,7 +131,11 @@ func Verify(input, inventory, missing string) error {
},
)

if err := mdoc.AddFile(sfile); err != nil {
mdocMtx.Lock()
err := mdoc.AddFile(sfile)
mdocMtx.Unlock()

if err != nil {
log.Error().Err(err).Msg("unable to add file to package")

return err
Expand Down

0 comments on commit 9a3eb8f

Please sign in to comment.