Files
Peter Adams 1118370ec4 Apply swift-format changes and CI (#472)
Motivation:

Standardised formatting makes the project cleaner to look at and work
on.

Modifications:

Setup swift-format with the same settings as Swift-NIO

Result:

Common formatting throughout
2024-10-29 13:09:54 +00:00

58 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 NIOCore
import NIOEmbedded
import NIOHTTP1
import NIOHTTP2
private 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
}