Use upstream targets for grpc-swift (#5825)

This commit is contained in:
Catena cyber 2021-05-24 22:48:18 +02:00 committed by GitHub
parent 878a05a092
commit 5fe68329ad
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 3 additions and 142 deletions

View File

@ -45,6 +45,4 @@ COPY llvmsymbol.diff $SRC
# specific to project
RUN git clone --depth 1 https://github.com/grpc/grpc-swift
COPY build.sh $SRC
COPY *.swift $SRC/
COPY patch.diff $SRC/
WORKDIR $SRC/grpc-swift

View File

@ -1,39 +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: "grpc-swift-fuzz",
dependencies: [
// Dependencies declare other packages that this package depends on.
.package(name: "grpc-swift", path: ".."),
],
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: "grpc-swift-fuzz",
dependencies: [
.target(name: "EchoImplementation"),
.product(name: "GRPC", package: "grpc-swift")
]),
.target(
name: "EchoImplementation",
dependencies: [
.target(name: "EchoModel"),
.product(name: "GRPC", package: "grpc-swift"),
],
path: "Sources/Echo/Implementation"
),
.target(
name: "EchoModel",
dependencies: [
.product(name: "GRPC", package: "grpc-swift"),
],
path: "Sources/Echo/Model"
),
]
)

View File

@ -33,14 +33,8 @@ ninja -j$(nproc) llvm-symbolizer
cp bin/llvm-symbolizer $OUT/
)
git apply $SRC/patch.diff
# build project
mkdir grpc-swift-fuzz
cd grpc-swift-fuzz
swift package init --type=executable
cp $SRC/fuzz_pipeline_configurator.swift Sources/grpc-swift-fuzz/main.swift
cp -r ../Sources/Examples/Echo Sources/
cp $SRC/Package.swift Package.swift
cd FuzzTesting
# Maybe we should have a helper script to set $SWIFT_FLAGS
# for instance about -DFUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION in -Xcc
swift build -c debug -Xswiftc -sanitize=fuzzer,address \
@ -51,7 +45,7 @@ swift build -c debug -Xswiftc -sanitize=fuzzer,address \
(
cd .build/debug/
find . -maxdepth 1 -type f -name "*fuzz" -executable | while read i; do cp $i $OUT/"$i"-debug; done
find . -maxdepth 1 -type f -name "*Fuzzer" -executable | while read i; do cp $i $OUT/"$i"-debug; done
)
swift build -c release -Xswiftc -sanitize=fuzzer,address \
-Xswiftc -parse-as-library -Xswiftc -static-stdlib \
@ -60,5 +54,5 @@ swift build -c release -Xswiftc -sanitize=fuzzer,address \
-Xcxx="-fsanitize=fuzzer-no-link,address"
(
cd .build/release/
find . -maxdepth 1 -type f -name "*fuzz" -executable | while read i; do cp $i $OUT/"$i"-release; done
find . -maxdepth 1 -type f -name "*Fuzzer" -executable | while read i; do cp $i $OUT/"$i"-release; done
)

View File

@ -1,30 +0,0 @@
import GRPC
import NIO
import EchoImplementation
@_cdecl("LLVMFuzzerTestOneInput")
public func test(_ start: UnsafeRawPointer, _ count: Int) -> CInt {
let bytes = UnsafeRawBufferPointer(start: start, count: count)
let channel = EmbeddedChannel()
let configuration = Server.Configuration(
target: .unixDomainSocket("/ignored"),
eventLoopGroup: channel.eventLoop,
serviceProviders: [EchoProvider()]
)
let handler = GRPCServerPipelineConfigurator(configuration: configuration)
var buffer = channel.allocator.buffer(capacity: count)
buffer.writeBytes(bytes)
do {
try channel.pipeline.addHandler(handler).wait()
try channel.writeInbound(buffer)
channel.embeddedEventLoop.run()
} catch {
}
do {
try _ = channel.finish(acceptAlreadyClosed: true)
} catch {
}
return 0
}

View File

@ -1,62 +0,0 @@
diff --git a/Sources/GRPC/GRPCServerPipelineConfigurator.swift b/Sources/GRPC/GRPCServerPipelineConfigurator.swift
index 4a0c143..1a02cd7 100644
--- a/Sources/GRPC/GRPCServerPipelineConfigurator.swift
+++ b/Sources/GRPC/GRPCServerPipelineConfigurator.swift
@@ -25,9 +25,9 @@ import NIOTLS
/// If TLS is enabled then the handler listens for an 'TLSUserEvent.handshakeCompleted' event and
/// configures the pipeline appropriately for the protocol negotiated via ALPN. If TLS is not
/// configured then the HTTP version is determined by parsing the inbound byte stream.
-final class GRPCServerPipelineConfigurator: ChannelInboundHandler, RemovableChannelHandler {
- internal typealias InboundIn = ByteBuffer
- internal typealias InboundOut = ByteBuffer
+public final class GRPCServerPipelineConfigurator: ChannelInboundHandler, RemovableChannelHandler {
+ public typealias InboundIn = ByteBuffer
+ public typealias InboundOut = ByteBuffer
/// The server configuration.
private let configuration: Server.Configuration
@@ -57,7 +57,7 @@ final class GRPCServerPipelineConfigurator: ChannelInboundHandler, RemovableChan
case configuring
}
- init(configuration: Server.Configuration) {
+ public init(configuration: Server.Configuration) {
if let tls = configuration.tls {
self.state = .notConfigured(alpn: .expected(required: tls.requireALPN))
} else {
@@ -251,7 +251,7 @@ final class GRPCServerPipelineConfigurator: ChannelInboundHandler, RemovableChan
// MARK: - Channel Handler
- internal func errorCaught(context: ChannelHandlerContext, error: Error) {
+ public func errorCaught(context: ChannelHandlerContext, error: Error) {
if let delegate = self.configuration.errorDelegate {
let baseError: Error
@@ -267,7 +267,7 @@ final class GRPCServerPipelineConfigurator: ChannelInboundHandler, RemovableChan
context.close(mode: .all, promise: nil)
}
- internal func userInboundEventTriggered(context: ChannelHandlerContext, event: Any) {
+ public func userInboundEventTriggered(context: ChannelHandlerContext, event: Any) {
switch self.state {
case let .notConfigured(alpn: .expected(required)):
if let event = event as? TLSUserEvent {
@@ -283,7 +283,7 @@ final class GRPCServerPipelineConfigurator: ChannelInboundHandler, RemovableChan
context.fireUserInboundEventTriggered(event)
}
- internal func channelRead(context: ChannelHandlerContext, data: NIOAny) {
+ public func channelRead(context: ChannelHandlerContext, data: NIOAny) {
self.bufferedReads.append(data)
switch self.state {
@@ -302,7 +302,7 @@ final class GRPCServerPipelineConfigurator: ChannelInboundHandler, RemovableChan
// Don't forward the reads: we'll do so when we have configured the pipeline.
}
- internal func removeHandler(
+ public func removeHandler(
context: ChannelHandlerContext,
removalToken: ChannelHandlerContext.RemovalToken
) {