diff options
Diffstat (limited to 'projects/swift-nio/fuzz_http1.swift')
-rw-r--r-- | projects/swift-nio/fuzz_http1.swift | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/projects/swift-nio/fuzz_http1.swift b/projects/swift-nio/fuzz_http1.swift new file mode 100644 index 000000000..065471a9a --- /dev/null +++ b/projects/swift-nio/fuzz_http1.swift @@ -0,0 +1,21 @@ +import NIOHTTP1 +import NIO + +@_cdecl("LLVMFuzzerTestOneInput") +public func test(_ start: UnsafeRawPointer, _ count: Int) -> CInt { + let bytes = UnsafeRawBufferPointer(start: start, count: count) + let channel = EmbeddedChannel() + var buffer = channel.allocator.buffer(capacity: count) + buffer.writeBytes(bytes) + do { + try channel.pipeline.addHandler(ByteToMessageHandler(HTTPRequestDecoder())).wait() + try channel.writeInbound(buffer) + channel.embeddedEventLoop.run() + } catch { + } + do { + try channel.finish(acceptAlreadyClosed: true) + } catch { + } + return 0 +} |