Parcourir la source

Use a C executable for fuzz testing (#1492)

Motivation:

Fuzz testing was accidentally broken in
https://github.com/grpc/grpc-swift/pull/1483.

Modifications:

- The compiler was looking for a 'ServerFuzzer_main' symbol which didn't
  exist ('ServerFuzzer' is an executable target).
- Add a 'ServerFuzzerLib' target containing the contents of the existing
  'ServerFuzzer' target.
- Change the 'ServerFuzzer' target to be a C module calling the API
  exposed by 'ServerFuzzerLib'

Result:

Fuzzing builds again.
George Barnett il y a 3 ans
Parent
commit
2bf2a164ce

+ 6 - 0
FuzzTesting/Package.swift

@@ -25,6 +25,12 @@ let package = Package(
   targets: [
     .executableTarget(
       name: "ServerFuzzer",
+      dependencies: [
+        .target(name: "ServerFuzzerLib"),
+      ]
+    ),
+    .target(
+      name: "ServerFuzzerLib",
       dependencies: [
         .product(name: "GRPC", package: "grpc-swift"),
         .product(name: "NIO", package: "swift-nio"),

+ 9 - 0
FuzzTesting/Sources/ServerFuzzer/src/serverfuzzer.c

@@ -0,0 +1,9 @@
+#include <inttypes.h>
+#include <stddef.h>
+
+// Provided by ServerFuzzerLib.
+int ServerFuzzer(const uint8_t *Data, size_t Size);
+
+int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
+  return ServerFuzzer(data, size);
+}

+ 1 - 1
FuzzTesting/Sources/ServerFuzzer/main.swift → FuzzTesting/Sources/ServerFuzzerLib/ServerFuzzer.swift

@@ -17,7 +17,7 @@ import EchoImplementation
 import GRPC
 import NIO
 
-@_cdecl("LLVMFuzzerTestOneInput")
+@_cdecl("ServerFuzzer")
 public func test(_ start: UnsafeRawPointer, _ count: Int) -> CInt {
   let bytes = UnsafeRawBufferPointer(start: start, count: count)