aboutsummaryrefslogtreecommitdiff
path: root/projects/swift-nio/fuzz_http1.swift
blob: 065471a9a26c546a74238318ac25bc2f47e83b35 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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
}