mirror of
https://github.com/apple/swift-nio-http2
synced 2026-11-22 04:30:43 +00:00
Motivation: Fuzzing is great, we should have a good sensible place to centralise a harness. Modifications: - Add a fuzzing harness. Result: There's a common way to do fuzzing.
59 lines
1.8 KiB
Swift
59 lines
1.8 KiB
Swift
//===----------------------------------------------------------------------===//
|
|
//
|
|
// This source file is part of the SwiftNIO open source project
|
|
//
|
|
// Copyright (c) 2021 Apple Inc. and the SwiftNIO project authors
|
|
// Licensed under Apache License v2.0
|
|
//
|
|
// See LICENSE.txt for license information
|
|
// See CONTRIBUTORS.txt for the list of SwiftNIO project authors
|
|
//
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
// Sources/protoc-gen-swift/main.swift - Protoc plugin main
|
|
//
|
|
// Copyright (c) 2020 - 2021 Apple Inc. and the project authors
|
|
// Licensed under Apache License v2.0 with Runtime Library Exception
|
|
//
|
|
// See LICENSE.txt for license information:
|
|
// https://github.com/apple/swift-protobuf/blob/main/LICENSE.txt
|
|
|
|
|
|
import Foundation
|
|
|
|
import NIO
|
|
import NIOHTTP1
|
|
import NIOHTTP2
|
|
|
|
fileprivate func fuzzInput(_ bytes: UnsafeRawBufferPointer) throws {
|
|
let channel = EmbeddedChannel()
|
|
defer {
|
|
_ = try? channel.finish()
|
|
}
|
|
_ = try channel.configureHTTP2Pipeline(
|
|
mode: .server,
|
|
initialLocalSettings: [HTTP2Setting(parameter: .maxConcurrentStreams, value: 1<<23)],
|
|
inboundStreamInitializer: nil
|
|
).wait()
|
|
try channel.connect(to: SocketAddress(unixDomainSocketPath: "/foo")).wait()
|
|
|
|
let buffer = channel.allocator.buffer(bytes: bytes)
|
|
try channel.writeInbound(buffer)
|
|
channel.embeddedEventLoop.run()
|
|
channel.pipeline.fireChannelInactive()
|
|
channel.embeddedEventLoop.run()
|
|
}
|
|
|
|
@_cdecl("LLVMFuzzerTestOneInput")
|
|
public func FuzzServer(_ start: UnsafeRawPointer, _ count: Int) -> CInt {
|
|
let bytes = UnsafeRawBufferPointer(start: start, count: count)
|
|
do {
|
|
let _ = try fuzzInput(bytes)
|
|
} catch {
|
|
// Errors parsing are to be expected since not all inputs will be well formed.
|
|
}
|
|
|
|
return 0
|
|
}
|