Skip to content

Commit 3daf9c2

Browse files
author
Samuel Groß
committed
Add very simple pre-processing of programs that will be mutated
Now we insert a few trivial values (ints, floats, strings) at the start of every program that we want to mutate in order to increase the number of available variables and avoid code patterns like const v1 = {"foo": RegExp, "bar": RegExp, "baz": RegExp}
1 parent 5688f9a commit 3daf9c2

File tree

3 files changed

+19
-11
lines changed

3 files changed

+19
-11
lines changed

Sources/Fuzzilli/Core/MutationEngine.swift

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public class MutationEngine: ComponentBase, FuzzEngine {
4646
/// as the intermediate results do not cause a runtime exception.
4747
public func fuzzOne(_ group: DispatchGroup) {
4848
var parent = fuzzer.corpus.randomElementForMutating()
49-
var program = parent
49+
var program = prepareForMutating(parent)
5050
for _ in 0..<numConsecutiveMutations {
5151
var mutator = fuzzer.mutators.randomElement()
5252
var mutated = false
@@ -75,4 +75,16 @@ public class MutationEngine: ComponentBase, FuzzEngine {
7575
}
7676
}
7777
}
78+
79+
/// Pre-processing of programs to facilitate mutations on them.
80+
/// Currently, this only adds a few trivial instructions at the start of the program to increase the number of available values.
81+
private func prepareForMutating(_ program: Program) -> Program {
82+
let b = fuzzer.makeBuilder()
83+
let valuesToGenerate = Int.random(in: 1...3)
84+
for _ in 0..<valuesToGenerate {
85+
b.run(chooseUniform(from: fuzzer.trivialCodeGenerators))
86+
}
87+
b.append(program)
88+
return b.finalize()
89+
}
7890
}

Sources/Fuzzilli/Core/ProgramBuilder.swift

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1024,7 +1024,10 @@ public class ProgramBuilder {
10241024
case .runningGenerators:
10251025
if !hasVisibleVariables {
10261026
// Can't run code generators if there are no visible variables, so generate some.
1027-
run(chooseUniform(from: fuzzer.trivialCodeGenerators))
1027+
let valuesToGenerate = Int.random(in: 1...3)
1028+
for _ in 0..<valuesToGenerate {
1029+
run(chooseUniform(from: fuzzer.trivialCodeGenerators))
1030+
}
10281031
assert(hasVisibleVariables)
10291032
}
10301033

@@ -1051,7 +1054,7 @@ public class ProgramBuilder {
10511054
}
10521055

10531056
/// Runs a code generator in the current context.
1054-
private func run(_ generator: CodeGenerator) {
1057+
public func run(_ generator: CodeGenerator) {
10551058
assert(generator.requiredContext.isSubset(of: context))
10561059

10571060
var inputs: [Variable] = []

Sources/Fuzzilli/Fuzzer.swift

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -105,18 +105,11 @@ public class Fuzzer {
105105
/// Fuzzer instances can be looked up from a dispatch queue through this key. See below.
106106
private static let dispatchQueueKey = DispatchSpecificKey<Fuzzer>()
107107

108-
/// List of CodeGenerators that don't require inputs and generate simple objects/values that can subsequently be used.
108+
/// List of trivial CodeGenerators that don't require inputs and generate simple values that can subsequently be used.
109109
public let trivialCodeGenerators: [CodeGenerator] = [
110110
CodeGenerators.get("IntegerGenerator"),
111111
CodeGenerators.get("StringGenerator"),
112-
CodeGenerators.get("BuiltinGenerator"),
113-
CodeGenerators.get("RegExpGenerator"),
114-
CodeGenerators.get("BigIntGenerator"),
115112
CodeGenerators.get("FloatGenerator"),
116-
CodeGenerators.get("FloatArrayGenerator"),
117-
CodeGenerators.get("IntArrayGenerator"),
118-
CodeGenerators.get("TypedArrayGenerator"),
119-
CodeGenerators.get("ObjectArrayGenerator"),
120113
]
121114

122115
/// Constructs a new fuzzer instance with the provided components.

0 commit comments

Comments
 (0)