Skip to content

Commit 231ff15

Browse files
authored
Update HowFuzzilliWorks.md (#514)
1 parent 5b49d1d commit 231ff15

1 file changed

Lines changed: 9 additions & 9 deletions

File tree

Docs/HowFuzzilliWorks.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ CodeGenerator("ComparisonGenerator", inputs: (.anything, .anything)) { b, lhs, r
187187

188188
This generator emits a comparison instruction (e.g. `==`) comparing two existing variables (of arbitrary type).
189189

190-
The default code generators can be found in [CodeGenerators.swift](https://github.com/googleprojectzero/fuzzilli/blob/main/Sources/Fuzzilli/CodeGen/CodeGenerators.swift) while custom code generators can be added for specific engines, for example to [trigger different levels of JITing](https://github.com/googleprojectzero/fuzzilli/blob/main/Sources/FuzzilliCli/Profiles/JSCProfile.swift).
190+
The default code generators can be found in [CodeGenerators.swift](https://github.com/googleprojectzero/fuzzilli/blob/main/Sources/Fuzzilli/CodeGen/CodeGenerators.swift) while custom code generators can be added for specific Javascript engines, for example to [trigger different levels of JITing](https://github.com/googleprojectzero/fuzzilli/blob/main/Sources/FuzzilliCli/Profiles/JSCProfile.swift).
191191

192192
Code generators are stored in a weighted list and are thus selected with different, currently [manually chosen weights](https://github.com/googleprojectzero/fuzzilli/blob/main/Sources/Fuzzilli/CodeGen/CodeGeneratorWeights.swift). This allows some degree of control over the distribution of the generated code, for example roughly how often arithmetic operations or method calls are performed, or how much control flow (if-else, loops, ...) is generated relative to data flow. Furthermore, CodeGenerators provide a simple way to steer Fuzzilli towards certain bug types by adding CodeGenerators that generate code fragments that have frequently resulted in bugs in the past, such as prototype changes, custom type conversion callbacks (e.g. valueOf), or indexed accessors.
193193

@@ -256,7 +256,7 @@ Up to this point, a code generator is a simple function that fetches zero or mor
256256

257257
```swift
258258
CodeGenerator("FunctionCallGenerator") { b in
259-
let function = b.randomJsVariable()
259+
let f = b.randomVariable()
260260
let arguments = [b.randomJsVariable(), b.randomJsVariable(), b.randomJsVariable()]
261261
b.callFunction(f, with: arguments)
262262
}
@@ -309,8 +309,8 @@ With type information available, the CodeGenerator from above can now request a
309309

310310
```swift
311311
CodeGenerator("FunctionCallGenerator") { b in
312-
let function = b.randomVariable(ofType: .function())
313-
let arguments = b.randomArguments(forCalling: function)
312+
let f = b.randomVariable(ofType: .function())
313+
let arguments = b.randomArguments(forCalling: f)
314314
b.callFunction(f, with: arguments)
315315
}
316316
```
@@ -716,7 +716,7 @@ CodeGenerator("ComputedPropertyAssignmentGenerator", inputs: .preferred(.object(
716716
},
717717
```
718718

719-
When running the first generator, the `ProgramBuilder.randomBuiltin` API will consult the static environment model to find an available builtin. In this case, the environment model may contain the following builtin: `bar: .function([] => .anything)`, which is then choosen. Next, code generation may select the `FunctionCallGenerator`. As it states that it would like a `.function()` as argument, the ProgramBuilder would (likely) select the previously loaded builtin. As its signature is known, no argument values are selected for the call and the return value is typed as `.anything`. Finally, code generation may pick the `ComputedPropertyAssignmentGenerator`. As there is currently no value of type `.object()` available, the return value of the function call would (likely) be selected as it has type `.anything`. This way, there is al least a chance that the value will be an object at runtime. As it cannot be ruled out that the value is not "nullish" (`null` or `undefined`), in which case a runtime exception would be raised, the code generator marks the operation as guarded. Putting everything together, the following code is generated for the function:
719+
When running the first generator, the `ProgramBuilder.randomBuiltin` API will consult the static environment model to find an available builtin. In this case, the environment model may contain the following builtin: `bar: .function([] => .anything)`, which is then choosen. Next, code generation may select the `FunctionCallGenerator`. As it states that it would like a `.function()` as argument, the ProgramBuilder would (likely) select the previously loaded builtin. As its signature is known, no argument values are selected for the call and the return value is typed as `.anything`. Finally, code generation may pick the `ComputedPropertyAssignmentGenerator`. As there is currently no value of type `.object()` available, the return value of the function call would (likely) be selected as it has type `.anything`. This way, there is at least a chance that the value will be an object at runtime. As it cannot be ruled out that the value is not "nullish" (`null` or `undefined`), in which case a runtime exception would be raised, the code generator marks the operation as guarded. Putting everything together, the following code is generated for the function:
720720

721721
```
722722
v4 <- BeginPlainFunction -> v5, v6
@@ -738,7 +738,7 @@ function f4(a5, a6) {
738738
return v8;
739739
}
740740
for (let v9 = 0; v9 < 100; v9++) {
741-
f6("foo", 42 * 1337);
741+
f4("foo", 42 * 1337);
742742
}
743743
```
744744

@@ -751,16 +751,16 @@ function f4(a5, a6) {
751751
return v8;
752752
}
753753
for (let v9 = 0; v9 < 100; v9++) {
754-
f6("foo", 42 * 1337);
754+
f4("foo", 42 * 1337);
755755
}
756756
```
757757

758758
The subsequent mutations may then change the generated program in all sorts of interesting (and less interesting) ways.
759759

760760
### Code Generation + Mutations: The HybridEngine
761-
The HybridEngine combines the code generation engine with the existing mutators. For that, it first selects a random ProgramTemplate, then generates a program from it, using the code generation engine as discussed previously. If the generated program is valid, it is further mutated a few times, using the algorithm that is also used by the Mutationengine.
761+
The HybridEngine combines the code generation engine with the existing mutators. For that, it first selects a random ProgramTemplate, then generates a program from it, using the code generation engine as discussed previously. If the generated program is valid, it is further mutated a few times, using the algorithm that is also used by the MutationEngine.
762762

763-
The high-level algorithm used by the hybrid engine is summarized by the image below.
763+
The high-level algorithm used by the HybridEngine is summarized by the image below.
764764

765765
![Hybrid Fuzzing Algorithm](images/hybrid_engine.png)
766766

0 commit comments

Comments
 (0)