Skip to content

Commit b47faae

Browse files
committed
fix some bugs
1 parent 6943a65 commit b47faae

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

fuzzing/fuzzer_worker.go

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,11 @@ func (fw *FuzzerWorker) updateMethods() {
264264
// It resolves the contract definition and ABI metadata needed for runtime execution. If the function
265265
// returns an error, the call sequence/corpus item is marked as invalid and will not be used for mutations.
266266
func (fw *FuzzerWorker) bindCorpusElement(currentIndex int) error {
267+
// Guard clause
268+
if currentIndex >= len(fw.sequenceGenerator.baseSequence) {
269+
return nil
270+
}
271+
267272
// Obtain the corpus element
268273
element := fw.sequenceGenerator.baseSequence[currentIndex]
269274

@@ -310,8 +315,8 @@ func (fw *FuzzerWorker) testNextCallSequence() ([]ShrinkCallSequenceRequest, err
310315
}()
311316

312317
// Initialize a new sequence within our sequence generator.
313-
var isCorpusSequence bool
314-
isCorpusSequence, err = fw.sequenceGenerator.InitializeNextSequence()
318+
var isNewSequence bool
319+
isNewSequence, err = fw.sequenceGenerator.InitializeNextSequence()
315320
if err != nil {
316321
return nil, err
317322
}
@@ -322,7 +327,7 @@ func (fw *FuzzerWorker) testNextCallSequence() ([]ShrinkCallSequenceRequest, err
322327
// Our "fetch next call" method will generate new calls as needed, if we are generating a new sequence.
323328
fetchElementFunc := func(currentIndex int) (*calls.CallSequenceElement, error) {
324329
// We need to prepare the corpus element for runtime execution if we are replaying a corpus sequence
325-
if isCorpusSequence {
330+
if !isNewSequence {
326331
err := fw.bindCorpusElement(currentIndex)
327332

328333
if err != nil {
@@ -387,7 +392,7 @@ func (fw *FuzzerWorker) testNextCallSequence() ([]ShrinkCallSequenceRequest, err
387392

388393
// If we encountered an error, report it.
389394
if err != nil {
390-
if isCorpusSequence {
395+
if !isNewSequence {
391396
fw.fuzzer.logger.Debug("DEBUG: failed to execute corpus sequence", err)
392397
fw.fuzzer.corpus.IncrementValid(false)
393398
} else {
@@ -401,7 +406,7 @@ func (fw *FuzzerWorker) testNextCallSequence() ([]ShrinkCallSequenceRequest, err
401406
}
402407

403408
// We successfully executed a corpus element
404-
if isCorpusSequence {
409+
if !isNewSequence {
405410
fw.fuzzer.corpus.IncrementValid(true)
406411
// If there are no shrink requests that means this is not a test result call sequence, so we can mark it for mutation.
407412
if len(shrinkCallSequenceRequests) == 0 {
@@ -411,7 +416,7 @@ func (fw *FuzzerWorker) testNextCallSequence() ([]ShrinkCallSequenceRequest, err
411416
}
412417

413418
// We don't want to save shrink results from corpus sequences since we already did.
414-
if !isCorpusSequence {
419+
if !isNewSequence {
415420
for i := 0; i < len(fw.shrinkCallSequenceRequests); i++ {
416421
shrinkCallSequenceRequests[i].RecordResultInCorpus = false
417422
}

0 commit comments

Comments
 (0)