Skip to content

Commit f7d051a

Browse files
committed
feature/void
1 parent 0e20cd5 commit f7d051a

13 files changed

+93
-0
lines changed

Sources/Fuzzilli/Base/ProgramBuilder.swift

+5
Original file line numberDiff line numberDiff line change
@@ -2039,6 +2039,11 @@ public class ProgramBuilder {
20392039
return emit(TypeOf(), withInputs: [v]).output
20402040
}
20412041

2042+
@discardableResult
2043+
public func void(_ v: Variable) -> Variable {
2044+
return emit(Void_(), withInputs: [v]).output
2045+
}
2046+
20422047
@discardableResult
20432048
public func testInstanceOf(_ v: Variable, _ type: Variable) -> Variable {
20442049
return emit(TestInstanceOf(), withInputs: [v, type]).output

Sources/Fuzzilli/CodeGen/CodeGeneratorWeights.swift

+1
Original file line numberDiff line numberDiff line change
@@ -192,4 +192,5 @@ public let codeGeneratorWeights = [
192192
"ApiConstructorCallGenerator": 15,
193193
"ApiMethodCallGenerator": 15,
194194
"ApiFunctionCallGenerator": 15,
195+
"VoidGenerator": 1,
195196
]

Sources/Fuzzilli/CodeGen/CodeGenerators.swift

+4
Original file line numberDiff line numberDiff line change
@@ -970,6 +970,10 @@ public let CodeGenerators: [CodeGenerator] = [
970970
b.compare(type, with: rhs, using: .strictEqual)
971971
},
972972

973+
CodeGenerator("VoidGenerator", inputs: .one) { b, val in
974+
b.void(val)
975+
},
976+
973977
CodeGenerator("InstanceOfGenerator", inputs: .preferred(.anything, .constructor())) { b, val, cls in
974978
b.testInstanceOf(val, cls)
975979
},

Sources/Fuzzilli/FuzzIL/Instruction.swift

+4
Original file line numberDiff line numberDiff line change
@@ -565,6 +565,8 @@ extension Instruction: ProtobufConvertible {
565565
}
566566
case .typeOf:
567567
$0.typeOf = Fuzzilli_Protobuf_TypeOf()
568+
case .void:
569+
$0.void = Fuzzilli_Protobuf_Void()
568570
case .testInstanceOf:
569571
$0.testInstanceOf = Fuzzilli_Protobuf_TestInstanceOf()
570572
case .testIn:
@@ -1042,6 +1044,8 @@ extension Instruction: ProtobufConvertible {
10421044
op = ConfigureComputedProperty(flags: flags, type: try convertEnum(p.type, PropertyType.allCases))
10431045
case .typeOf:
10441046
op = TypeOf()
1047+
case .void:
1048+
op = Void_()
10451049
case .testInstanceOf:
10461050
op = TestInstanceOf()
10471051
case .testIn:

Sources/Fuzzilli/FuzzIL/JSTyper.swift

+3
Original file line numberDiff line numberDiff line change
@@ -675,6 +675,9 @@ public struct JSTyper: Analyzer {
675675
case .typeOf:
676676
set(instr.output, .string)
677677

678+
case .void:
679+
set(instr.output, .undefined)
680+
678681
case .testInstanceOf:
679682
set(instr.output, .boolean)
680683

Sources/Fuzzilli/FuzzIL/JsOperations.swift

+8
Original file line numberDiff line numberDiff line change
@@ -1030,6 +1030,14 @@ final class TypeOf: JsOperation {
10301030
}
10311031
}
10321032

1033+
final class Void_: JsOperation {
1034+
override var opcode: Opcode { .void(self) }
1035+
1036+
init() {
1037+
super.init(numInputs: 1, numOutputs: 1)
1038+
}
1039+
}
1040+
10331041
final class TestInstanceOf: JsOperation {
10341042
override var opcode: Opcode { .testInstanceOf(self) }
10351043

Sources/Fuzzilli/FuzzIL/Opcodes.swift

+1
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ enum Opcode {
106106
case deleteComputedProperty(DeleteComputedProperty)
107107
case configureComputedProperty(ConfigureComputedProperty)
108108
case typeOf(TypeOf)
109+
case void(Void_)
109110
case testInstanceOf(TestInstanceOf)
110111
case testIn(TestIn)
111112
case beginPlainFunction(BeginPlainFunction)

Sources/Fuzzilli/Lifting/FuzzILLifter.swift

+3
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,9 @@ public class FuzzILLifter: Lifter {
366366
case .typeOf:
367367
w.emit("\(output()) <- TypeOf \(input(0))")
368368

369+
case .void:
370+
w.emit("\(output()) <- Void_ \(input(0))")
371+
369372
case .testInstanceOf:
370373
w.emit("\(output()) <- TestInstanceOf \(input(0)), \(input(1))")
371374

Sources/Fuzzilli/Lifting/JavaScriptLifter.swift

+4
Original file line numberDiff line numberDiff line change
@@ -642,6 +642,10 @@ public class JavaScriptLifter: Lifter {
642642
let expr = UnaryExpression.new() + "typeof " + input(0)
643643
w.assign(expr, to: instr.output)
644644

645+
case .void:
646+
let expr = UnaryExpression.new() + "void " + input(0)
647+
w.assign(expr, to: instr.output)
648+
645649
case .testInstanceOf:
646650
let lhs = input(0)
647651
let rhs = input(1)

Sources/Fuzzilli/Protobuf/operations.pb.swift

+29
Original file line numberDiff line numberDiff line change
@@ -1278,6 +1278,16 @@ public struct Fuzzilli_Protobuf_TypeOf: Sendable {
12781278
public init() {}
12791279
}
12801280

1281+
public struct Fuzzilli_Protobuf_Void: Sendable {
1282+
// SwiftProtobuf.Message conformance is added in an extension below. See the
1283+
// `Message` and `Message+*Additions` files in the SwiftProtobuf library for
1284+
// methods supported on all messages.
1285+
1286+
public var unknownFields = SwiftProtobuf.UnknownStorage()
1287+
1288+
public init() {}
1289+
}
1290+
12811291
public struct Fuzzilli_Protobuf_TestInstanceOf: Sendable {
12821292
// SwiftProtobuf.Message conformance is added in an extension below. See the
12831293
// `Message` and `Message+*Additions` files in the SwiftProtobuf library for
@@ -4885,6 +4895,25 @@ extension Fuzzilli_Protobuf_TypeOf: SwiftProtobuf.Message, SwiftProtobuf._Messag
48854895
}
48864896
}
48874897

4898+
extension Fuzzilli_Protobuf_Void: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding {
4899+
public static let protoMessageName: String = _protobuf_package + ".Void"
4900+
public static let _protobuf_nameMap = SwiftProtobuf._NameMap()
4901+
4902+
public mutating func decodeMessage<D: SwiftProtobuf.Decoder>(decoder: inout D) throws {
4903+
while let _ = try decoder.nextFieldNumber() {
4904+
}
4905+
}
4906+
4907+
public func traverse<V: SwiftProtobuf.Visitor>(visitor: inout V) throws {
4908+
try unknownFields.traverse(visitor: &visitor)
4909+
}
4910+
4911+
public static func ==(lhs: Fuzzilli_Protobuf_Void, rhs: Fuzzilli_Protobuf_Void) -> Bool {
4912+
if lhs.unknownFields != rhs.unknownFields {return false}
4913+
return true
4914+
}
4915+
}
4916+
48884917
extension Fuzzilli_Protobuf_TestInstanceOf: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding {
48894918
public static let protoMessageName: String = _protobuf_package + ".TestInstanceOf"
48904919
public static let _protobuf_nameMap = SwiftProtobuf._NameMap()

Sources/Fuzzilli/Protobuf/operations.proto

+3
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,9 @@ message ConfigureComputedProperty {
337337
message TypeOf {
338338
}
339339

340+
message Void {
341+
}
342+
340343
message TestInstanceOf {
341344
}
342345

Sources/Fuzzilli/Protobuf/program.pb.swift

+27
Original file line numberDiff line numberDiff line change
@@ -680,6 +680,14 @@ public struct Fuzzilli_Protobuf_Instruction: Sendable {
680680
set {operation = .typeOf(newValue)}
681681
}
682682

683+
public var void: Fuzzilli_Protobuf_Void {
684+
get {
685+
if case .void(let v)? = operation {return v}
686+
return Fuzzilli_Protobuf_Void()
687+
}
688+
set {operation = .void(newValue)}
689+
}
690+
683691
public var testInstanceOf: Fuzzilli_Protobuf_TestInstanceOf {
684692
get {
685693
if case .testInstanceOf(let v)? = operation {return v}
@@ -1554,6 +1562,7 @@ public struct Fuzzilli_Protobuf_Instruction: Sendable {
15541562
case deleteComputedProperty(Fuzzilli_Protobuf_DeleteComputedProperty)
15551563
case configureComputedProperty(Fuzzilli_Protobuf_ConfigureComputedProperty)
15561564
case typeOf(Fuzzilli_Protobuf_TypeOf)
1565+
case void(Fuzzilli_Protobuf_Void)
15571566
case testInstanceOf(Fuzzilli_Protobuf_TestInstanceOf)
15581567
case testIn(Fuzzilli_Protobuf_TestIn)
15591568
case beginPlainFunction(Fuzzilli_Protobuf_BeginPlainFunction)
@@ -1881,6 +1890,7 @@ extension Fuzzilli_Protobuf_Instruction: SwiftProtobuf.Message, SwiftProtobuf._M
18811890
177: .same(proto: "explore"),
18821891
178: .same(proto: "probe"),
18831892
179: .same(proto: "fixup"),
1893+
180: .same(proto: "void"),
18841894
]
18851895

18861896
public mutating func decodeMessage<D: SwiftProtobuf.Decoder>(decoder: inout D) throws {
@@ -4199,6 +4209,19 @@ extension Fuzzilli_Protobuf_Instruction: SwiftProtobuf.Message, SwiftProtobuf._M
41994209
self.operation = .fixup(v)
42004210
}
42014211
}()
4212+
case 180: try {
4213+
var v: Fuzzilli_Protobuf_Void?
4214+
var hadOneofValue = false
4215+
if let current = self.operation {
4216+
hadOneofValue = true
4217+
if case .void(let m) = current {v = m}
4218+
}
4219+
try decoder.decodeSingularMessageField(value: &v)
4220+
if let v = v {
4221+
if hadOneofValue {try decoder.handleConflictingOneOf()}
4222+
self.operation = .void(v)
4223+
}
4224+
}()
42024225
default: break
42034226
}
42044227
}
@@ -4529,6 +4552,10 @@ extension Fuzzilli_Protobuf_Instruction: SwiftProtobuf.Message, SwiftProtobuf._M
45294552
guard case .typeOf(let v)? = self.operation else { preconditionFailure() }
45304553
try visitor.visitSingularMessageField(value: v, fieldNumber: 80)
45314554
}()
4555+
case .void?: try {
4556+
guard case .void(let v)? = self.operation else { preconditionFailure() }
4557+
try visitor.visitSingularMessageField(value: v, fieldNumber: 80)
4558+
}()
45324559
case .testInstanceOf?: try {
45334560
guard case .testInstanceOf(let v)? = self.operation else { preconditionFailure() }
45344561
try visitor.visitSingularMessageField(value: v, fieldNumber: 81)

Sources/Fuzzilli/Protobuf/program.proto

+1
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,7 @@ message Instruction {
203203
Explore explore = 177;
204204
Probe probe = 178;
205205
Fixup fixup = 179;
206+
Void void = 180;
206207
}
207208
}
208209

0 commit comments

Comments
 (0)