From cab0c4ea566d619b437f5ad885e82b4cb0cd7eab Mon Sep 17 00:00:00 2001 From: Yi2255 Date: Thu, 14 Nov 2024 11:10:45 +0000 Subject: [PATCH 1/3] fix non-iteratrable input of yieldEach --- .../CodeGen/CodeGeneratorWeights.swift | 1 + Sources/Fuzzilli/CodeGen/CodeGenerators.swift | 24 +++++++++++-------- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/Sources/Fuzzilli/CodeGen/CodeGeneratorWeights.swift b/Sources/Fuzzilli/CodeGen/CodeGeneratorWeights.swift index 9ce5be34a..f7d43fd07 100644 --- a/Sources/Fuzzilli/CodeGen/CodeGeneratorWeights.swift +++ b/Sources/Fuzzilli/CodeGen/CodeGeneratorWeights.swift @@ -91,6 +91,7 @@ public let codeGeneratorWeights = [ "ConstructorGenerator": 5, "SubroutineReturnGenerator": 3, "YieldGenerator": 2, + "YieldEachGenerator": 2, "AwaitGenerator": 2, "PropertyRetrievalGenerator": 20, "PropertyAssignmentGenerator": 20, diff --git a/Sources/Fuzzilli/CodeGen/CodeGenerators.swift b/Sources/Fuzzilli/CodeGen/CodeGenerators.swift index f8a9cd5f7..616106d93 100644 --- a/Sources/Fuzzilli/CodeGen/CodeGenerators.swift +++ b/Sources/Fuzzilli/CodeGen/CodeGenerators.swift @@ -775,7 +775,9 @@ public let CodeGenerators: [CodeGenerator] = [ if probability(0.5) { b.yield(b.randomVariable()) } else { - b.yieldEach(b.randomVariable()) + let randomVariables = b.randomVariables(n: Int.random(in: 1...5)) + let array = b.createArray(with: randomVariables) + b.yieldEach(array) } b.doReturn(b.randomVariable()) } @@ -807,7 +809,9 @@ public let CodeGenerators: [CodeGenerator] = [ if probability(0.5) { b.yield(b.randomVariable()) } else { - b.yieldEach(b.randomVariable()) + let randomVariables = b.randomVariables(n: Int.random(in: 1...5)) + let array = b.createArray(with: randomVariables) + b.yieldEach(array) } b.doReturn(b.randomVariable()) } @@ -1077,18 +1081,18 @@ public let CodeGenerators: [CodeGenerator] = [ CodeGenerator("YieldGenerator", inContext: .generatorFunction, inputs: .one) { b, val in assert(b.context.contains(.generatorFunction)) - if probability(0.5) { - if probability(0.9) { - b.yield(val) - } else { - b.yield() - } + if probability(0.9) { + b.yield(val) } else { - // TODO only do this when the value is iterable? - b.yieldEach(val) + b.yield() } }, + CodeGenerator("YieldEachGenerator", inContext: .generatorFunction, inputs: .required(.iterable)) { b, val in + assert(b.context.contains(.generatorFunction)) + b.yieldEach(val) + }, + CodeGenerator("AwaitGenerator", inContext: .asyncFunction, inputs: .one) { b, val in assert(b.context.contains(.asyncFunction)) b.await(val) From 2cf0d4b7c2bb555187e4edc900321b9425b6d887 Mon Sep 17 00:00:00 2001 From: Yi2255 Date: Thu, 14 Nov 2024 11:46:48 +0000 Subject: [PATCH 2/3] Increase weight to 5 for SubroutineReturnGenerator and YieldGenerator --- Sources/Fuzzilli/CodeGen/CodeGeneratorWeights.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sources/Fuzzilli/CodeGen/CodeGeneratorWeights.swift b/Sources/Fuzzilli/CodeGen/CodeGeneratorWeights.swift index f7d43fd07..ea415051b 100644 --- a/Sources/Fuzzilli/CodeGen/CodeGeneratorWeights.swift +++ b/Sources/Fuzzilli/CodeGen/CodeGeneratorWeights.swift @@ -89,8 +89,8 @@ public let codeGeneratorWeights = [ "AsyncArrowFunctionGenerator": 1, "AsyncGeneratorFunctionGenerator": 1, "ConstructorGenerator": 5, - "SubroutineReturnGenerator": 3, - "YieldGenerator": 2, + "SubroutineReturnGenerator": 5, + "YieldGenerator": 5, "YieldEachGenerator": 2, "AwaitGenerator": 2, "PropertyRetrievalGenerator": 20, From bd9c14707d13a90c0e44a2943f9d2798391c44c5 Mon Sep 17 00:00:00 2001 From: Yi2255 Date: Thu, 14 Nov 2024 21:34:08 +0000 Subject: [PATCH 3/3] Increase weight to 5 for YieldGenerator and YieldEachGenerator --- Sources/Fuzzilli/CodeGen/CodeGeneratorWeights.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sources/Fuzzilli/CodeGen/CodeGeneratorWeights.swift b/Sources/Fuzzilli/CodeGen/CodeGeneratorWeights.swift index ea415051b..bda9a0d7b 100644 --- a/Sources/Fuzzilli/CodeGen/CodeGeneratorWeights.swift +++ b/Sources/Fuzzilli/CodeGen/CodeGeneratorWeights.swift @@ -89,9 +89,9 @@ public let codeGeneratorWeights = [ "AsyncArrowFunctionGenerator": 1, "AsyncGeneratorFunctionGenerator": 1, "ConstructorGenerator": 5, - "SubroutineReturnGenerator": 5, + "SubroutineReturnGenerator": 3, "YieldGenerator": 5, - "YieldEachGenerator": 2, + "YieldEachGenerator": 5, "AwaitGenerator": 2, "PropertyRetrievalGenerator": 20, "PropertyAssignmentGenerator": 20,