diff options
| author | Aleksandr Nogikh <nogikh@google.com> | 2024-04-05 15:15:21 +0200 |
|---|---|---|
| committer | Aleksandr Nogikh <nogikh@google.com> | 2024-04-05 13:59:32 +0000 |
| commit | 02474d9d95115e5355d1648fd07ca18d219715bd (patch) | |
| tree | 82fdd26bd79bb9f7ee2f4f8bd8cbabb222647e8e /pkg/corpus | |
| parent | 77230c294a419a97f63f155760d210bed1bc26a8 (diff) | |
pkg/corpus: avoid a race in Corpus.Minimize()
The following two operations were in conflict:
1) Overwriting of corpus.ProgramsList in Minimize().
2) ProgramsList.ChooseProgram() that used its own mutex.
Instead of overwriting the object, let's create a new one.
Diffstat (limited to 'pkg/corpus')
| -rw-r--r-- | pkg/corpus/corpus.go | 9 | ||||
| -rw-r--r-- | pkg/corpus/minimize.go | 4 |
2 files changed, 8 insertions, 5 deletions
diff --git a/pkg/corpus/corpus.go b/pkg/corpus/corpus.go index c513d2303..19dfee483 100644 --- a/pkg/corpus/corpus.go +++ b/pkg/corpus/corpus.go @@ -22,7 +22,7 @@ type Corpus struct { signal signal.Signal // total signal of all items cover cover.Cover // total coverage of all items updates chan<- NewItemEvent - ProgramsList + *ProgramsList } func NewCorpus(ctx context.Context) *Corpus { @@ -31,9 +31,10 @@ func NewCorpus(ctx context.Context) *Corpus { func NewMonitoredCorpus(ctx context.Context, updates chan<- NewItemEvent) *Corpus { return &Corpus{ - ctx: ctx, - progs: make(map[string]*Item), - updates: updates, + ctx: ctx, + progs: make(map[string]*Item), + updates: updates, + ProgramsList: &ProgramsList{}, } } diff --git a/pkg/corpus/minimize.go b/pkg/corpus/minimize.go index b47816ccf..938bd1d2e 100644 --- a/pkg/corpus/minimize.go +++ b/pkg/corpus/minimize.go @@ -32,7 +32,9 @@ func (corpus *Corpus) Minimize(cover bool) { }) corpus.progs = make(map[string]*Item) - corpus.ProgramsList = ProgramsList{} + // ProgramsList has its own mutex, so it'd be unsafe to + // overwrite it here, so let's create a new object. + corpus.ProgramsList = &ProgramsList{} for _, ctx := range signal.Minimize(inputs) { inp := ctx.(*Item) corpus.progs[inp.Sig] = inp |
