aboutsummaryrefslogtreecommitdiffhomepage
path: root/projects/swift-protobuf
diff options
context:
space:
mode:
authorGravatar Catena cyber <35799796+catenacyber@users.noreply.github.com>2021-04-14 15:08:53 +0200
committerGravatar GitHub <noreply@github.com>2021-04-14 06:08:53 -0700
commit3035d0a163d40c8e1084d5a895304c7f3a6aef3f (patch)
treef5677dda463a806f6bbf14f2ebf17ee5c61df86b /projects/swift-protobuf
parent1f38631d2cfc601d1c654b5d5710e652dabf03ee (diff)
Uses upstream repository fuzz targets for swift-protobuf (#5612)
Diffstat (limited to 'projects/swift-protobuf')
-rw-r--r--projects/swift-protobuf/Dockerfile3
-rw-r--r--projects/swift-protobuf/Package.swift19
-rwxr-xr-xprojects/swift-protobuf/build.sh21
-rw-r--r--projects/swift-protobuf/fuzz_binary.swift16
4 files changed, 12 insertions, 47 deletions
diff --git a/projects/swift-protobuf/Dockerfile b/projects/swift-protobuf/Dockerfile
index d154e588..871613f3 100644
--- a/projects/swift-protobuf/Dockerfile
+++ b/projects/swift-protobuf/Dockerfile
@@ -39,5 +39,4 @@ RUN git clone --depth 1 https://github.com/llvm/llvm-project.git
RUN git clone --depth 1 https://github.com/apple/swift-protobuf.git
COPY build.sh $SRC
COPY llvmsymbol.diff $SRC
-COPY *.swift $SRC/
-WORKDIR $SRC/
+WORKDIR $SRC/swift-protobuf
diff --git a/projects/swift-protobuf/Package.swift b/projects/swift-protobuf/Package.swift
deleted file mode 100644
index 78042f2c..00000000
--- a/projects/swift-protobuf/Package.swift
+++ /dev/null
@@ -1,19 +0,0 @@
-// swift-tools-version:5.3
-// The swift-tools-version declares the minimum version of Swift required to build this package.
-
-import PackageDescription
-
-let package = Package(
- name: "swift-protobuf-fuzz",
- dependencies: [
- // Dependencies declare other packages that this package depends on.
- .package(name: "SwiftProtobuf", path: "../swift-protobuf"),
- ],
- targets: [
- // Targets are the basic building blocks of a package. A target can define a module or a test suite.
- // Targets can depend on other targets in this package, and on products in packages this package depends on.
- .target(
- name: "swift-protobuf-fuzz",
- dependencies: ["SwiftProtobuf"]),
- ]
-)
diff --git a/projects/swift-protobuf/build.sh b/projects/swift-protobuf/build.sh
index 19c47dc3..c09fe377 100755
--- a/projects/swift-protobuf/build.sh
+++ b/projects/swift-protobuf/build.sh
@@ -16,7 +16,7 @@
################################################################################
(
-cd llvm-project
+cd $SRC/llvm-project
git apply ../llvmsymbol.diff
cmake -G "Ninja" -DLIBCXX_ENABLE_SHARED=OFF -DLIBCXX_ENABLE_STATIC_ABI_LIBRARY=ON -DLIBCXXABI_ENABLE_SHARED=OFF -DCMAKE_BUILD_TYPE=Release -DLLVM_TARGETS_TO_BUILD=X86 -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ -DLLVM_BUILD_TESTS=OFF -DLLVM_INCLUDE_TESTS=OFF llvm
ninja -j$(nproc) llvm-symbolizer
@@ -24,13 +24,14 @@ cp bin/llvm-symbolizer $OUT/
)
# build project
-mkdir swift-protobuf-fuzz
-cd swift-protobuf-fuzz
-swift package init --type=executable
-cp $SRC/fuzz_binary.swift Sources/swift-protobuf-fuzz/main.swift
-cp $SRC/Package.swift Package.swift
-cp ../swift-protobuf/Tests/SwiftProtobufTests/unittest.pb.swift Sources/swift-protobuf-fuzz/
-cp ../swift-protobuf/Tests/SwiftProtobufTests/unittest_import.pb.swift Sources/swift-protobuf-fuzz/
-cp ../swift-protobuf/Tests/SwiftProtobufTests/unittest_import_public.pb.swift Sources/swift-protobuf-fuzz/
+cd FuzzTesting
swift build -c debug -Xswiftc -sanitize=address,fuzzer -Xswiftc -parse-as-library -Xswiftc -static-stdlib -Xswiftc -use-ld=/usr/bin/ld --static-swift-stdlib --sanitize=address
-cp .build/x86_64-unknown-linux-gnu/debug/swift-protobuf-fuzz $OUT/
+(
+cd .build/debug/
+find . -maxdepth 1 -type f -name "Fuzz*" -executable | while read i; do cp $i $OUT/"$i"_debug; done
+)
+swift build -c release -Xswiftc -sanitize=address,fuzzer -Xswiftc -parse-as-library -Xswiftc -static-stdlib -Xswiftc -use-ld=/usr/bin/ld --static-swift-stdlib --sanitize=address
+(
+cd .build/release/
+find . -maxdepth 1 -type f -name "Fuzz*" -executable | while read i; do cp $i $OUT/"$i"_release; done
+)
diff --git a/projects/swift-protobuf/fuzz_binary.swift b/projects/swift-protobuf/fuzz_binary.swift
deleted file mode 100644
index bbb375e1..00000000
--- a/projects/swift-protobuf/fuzz_binary.swift
+++ /dev/null
@@ -1,16 +0,0 @@
-import Foundation
-import SwiftProtobuf
-
-@_cdecl("LLVMFuzzerTestOneInput")
-public func test(_ start: UnsafeRawPointer, _ count: Int) -> CInt {
- let bytes = UnsafeRawBufferPointer(start: start, count: count)
- var options = BinaryDecodingOptions()
- options.messageDepthLimit = 256
- do {
- let _ = try ProtobufUnittest_NestedTestAllTypes(serializedData: Data(bytes),
- options: options)
- } catch let e {
- }
- return 0
-}
-