Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new mutation strategy - callSeqGenFuncDuplicateAtRandom #424

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions fuzzing/fuzzer_worker_sequence_generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,13 @@ func NewCallSequenceGenerator(worker *FuzzerWorker, config *CallSequenceGenerato
},
new(big.Int).SetUint64(config.RandomUnmodifiedCorpusTailWeight),
),
randomutils.NewWeightedRandomChoice(
CallSequenceGeneratorMutationStrategy{
CallSequenceGeneratorFunc: callSeqGenFuncDuplicateAtRandom,
PrefetchModifyCallFunc: nil,
},
new(big.Int).SetUint64(config.RandomUnmodifiedCorpusTailWeight),
),
randomutils.NewWeightedRandomChoice(
CallSequenceGeneratorMutationStrategy{
CallSequenceGeneratorFunc: callSeqGenFuncSpliceAtRandom,
Expand Down Expand Up @@ -380,6 +387,20 @@ func callSeqGenFuncCorpusTail(sequenceGenerator *CallSequenceGenerator, sequence
return nil
}

// callSeqGenFuncDuplicateAtRandom is a CallSequenceGeneratorFunc which prepares a CallSequenceGenerator to generate a sequence
// which duplicates a call sequence element at index N and inserts it at N+1
// if random index is len(sequence)-1, it inserts the duplicated call sequence element at N-1
func callSeqGenFuncDuplicateAtRandom(sequenceGenerator *CallSequenceGenerator, sequence calls.CallSequence) error {
randIndex := sequenceGenerator.worker.randomProvider.Intn(len(sequence))
duplicatedElement := sequence[randIndex]
if randIndex == len(sequence)-1 {
sequence[randIndex-1] = duplicatedElement
} else {
sequence[randIndex+1] = duplicatedElement
}
return nil
}

// callSeqGenFuncSpliceAtRandom is a CallSequenceGeneratorFunc which prepares a CallSequenceGenerator to generate a
// sequence which is based off of two corpus call sequence entries, from which a random length head and tail are
// respectively sliced and joined together.
Expand Down