blob: eaa847a5f4baf6c3c68701119987b818fc15bf5b [file] [log] [blame]
// WARNING: This file is machine generated by fidlgen.
#include <lib/async-loop/cpp/loop.h>
#include <lib/async-loop/default.h>
#include <lib/fidl/cpp/fuzzing/fuzzer.h>
#include <lib/fidl/cpp/interface_ptr.h>
#include <lib/zx/channel.h>
#include <test/name/cpp/libfuzzer.h>
#include <zircon/errors.h>
#include <zircon/syscalls.h>
#include <zircon/types.h>
using namespace ::fuzzing;
using namespace ::test::name;
// Add //build/fuzzing:fuzzing_verbose_logging to a GN target's configs to
// enable.
#if FUZZING_VERBOSE_LOGGING
#include <stdio.h>
#define xprintf(fmt...) printf(fmt)
#else
#define xprintf(fmt...) \
do { \
} while (0)
#endif
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data_, size_t size_) {
static ::async::Loop* loop_ = nullptr;
if (loop_ == nullptr) {
xprintf("Starting client async loop\n");
loop_ = new ::async::Loop(&kAsyncLoopConfigAttachToCurrentThread);
}
// Must fuzz some protocol; first two bytes used to select protocol and
// method.
if (size_ < 2) {
xprintf("Early exit: Input too small: %zu\n", size_);
return 0;
}
size_ -= 2;
uint8_t protocol_selector_ = data_[0];
uint8_t protocol_selection_ = protocol_selector_ % 3;
xprintf("Starting fuzzer with %zu bytes of data\n", size_);
// Hardcode mutually-exclusive if blocks that selects exactly one protocol.
zx_status_t status_;
if (protocol_selection_ == 0) {
#if !defined(PROTOCOL_test_name_ChannelProtocol)
// Selected protocol from FIDL file that is not part of this fuzzer.
xprintf("Early exit: Chose disabled protocol: test_name_ChannelProtocol\n");
return 0;
#else
::fidl::InterfacePtr< ::test::name::ChannelProtocol> protocol_;
xprintf("Starting test_name_ChannelProtocol service\n");
::fidl::fuzzing::Fuzzer< ::test::name::ChannelProtocol> fuzzer_(
loop_->dispatcher());
if ((status_ = fuzzer_.Init()) != ZX_OK) {
xprintf("Early exit: fuzzer.Init returned bad status: %d\n", status_);
return 0;
}
if ((status_ = fuzzer_.BindService()) != ZX_OK) {
xprintf("Early exit: fuzzer.BindService returned bad status: %d\n",
status_);
return 0;
}
if ((status_ = fuzzer_.BindClient(&protocol_, loop_->dispatcher())) !=
ZX_OK) {
xprintf("Early exit: fuzzer.BindClient returned bad status: %d\n",
status_);
return 0;
}
FuzzInput src_(data_, size_);
uint8_t method_selector_ = data_[1];
uint8_t method_selection_ = method_selector_ % 4;
if (method_selection_ == 0) {
#if !(ALL_METHODS || defined(METHOD_MethodA))
// Selected method from protocol that is not part of this fuzzer.
xprintf("Early exit: Chose disabled method: MethodA\n");
return 0;
#else
const size_t min_size_ = MinSize<int64_t>() + MinSize<int64_t>();
// Must have enough bytes for input.
if (size_ < min_size_) {
xprintf("Early exit: Input size too small: %zu < %zu\n", size_,
min_size_);
return 0;
}
const size_t slack_size_ = size_ - min_size_;
const size_t slack_size_per_param = slack_size_ / 2;
xprintf("Allocating parameters with %zu bytes (%zu bytes each)\n",
slack_size_, slack_size_per_param);
size_t param_size_;
param_size_ = MinSize<int64_t>() + slack_size_per_param;
xprintf("Allocating %zu bytes for int64_t a\n", param_size_);
int64_t a = Allocate<int64_t>{}(&src_, &param_size_);
param_size_ = MinSize<int64_t>() + slack_size_per_param;
xprintf("Allocating %zu bytes for int64_t b\n", param_size_);
int64_t b = Allocate<int64_t>{}(&src_, &param_size_);
xprintf("Invoking method test_name_ChannelProtocol.MethodA\n");
protocol_->MethodA(std::move(a), std::move(b));
#endif
}
if (method_selection_ == 1) {
#if !(ALL_METHODS || defined(METHOD_EventA))
// Selected method from protocol that is not part of this fuzzer.
xprintf("Early exit: Chose disabled method: EventA\n");
return 0;
#else
const size_t min_size_ = ;
// Must have enough bytes for input.
if (size_ < min_size_) {
xprintf("Early exit: Input size too small: %zu < %zu\n", size_,
min_size_);
return 0;
}
const size_t slack_size_ = size_ - min_size_;
const size_t slack_size_per_param = slack_size_ / 0;
xprintf("Allocating parameters with %zu bytes (%zu bytes each)\n",
slack_size_, slack_size_per_param);
size_t param_size_;
xprintf("Invoking method test_name_ChannelProtocol.EventA\n");
protocol_->EventA(
[signaller = fuzzer_.NewCallbackSignaller()](int64_t a, int64_t b) {
xprintf("Invoked test_name_ChannelProtocol.EventA\n");
zx_status_t status_ = signaller.SignalCallback();
if (status_ != ZX_OK) {
xprintf("signaller.SignalCallback returned bad status: %d\n",
status_);
}
});
#endif
}
if (method_selection_ == 2) {
#if !(ALL_METHODS || defined(METHOD_MethodB))
// Selected method from protocol that is not part of this fuzzer.
xprintf("Early exit: Chose disabled method: MethodB\n");
return 0;
#else
const size_t min_size_ = MinSize<int64_t>() + MinSize<int64_t>();
// Must have enough bytes for input.
if (size_ < min_size_) {
xprintf("Early exit: Input size too small: %zu < %zu\n", size_,
min_size_);
return 0;
}
const size_t slack_size_ = size_ - min_size_;
const size_t slack_size_per_param = slack_size_ / 2;
xprintf("Allocating parameters with %zu bytes (%zu bytes each)\n",
slack_size_, slack_size_per_param);
size_t param_size_;
param_size_ = MinSize<int64_t>() + slack_size_per_param;
xprintf("Allocating %zu bytes for int64_t a\n", param_size_);
int64_t a = Allocate<int64_t>{}(&src_, &param_size_);
param_size_ = MinSize<int64_t>() + slack_size_per_param;
xprintf("Allocating %zu bytes for int64_t b\n", param_size_);
int64_t b = Allocate<int64_t>{}(&src_, &param_size_);
xprintf("Invoking method test_name_ChannelProtocol.MethodB\n");
protocol_->MethodB(
std::move(a), std::move(b),
[signaller = fuzzer_.NewCallbackSignaller()](int64_t result) {
xprintf("Invoked test_name_ChannelProtocol.MethodB\n");
zx_status_t status_ = signaller.SignalCallback();
if (status_ != ZX_OK) {
xprintf("signaller.SignalCallback returned bad status: %d\n",
status_);
}
});
#endif
}
if (method_selection_ == 3) {
#if !(ALL_METHODS || defined(METHOD_MutateSocket))
// Selected method from protocol that is not part of this fuzzer.
xprintf("Early exit: Chose disabled method: MutateSocket\n");
return 0;
#else
const size_t min_size_ = MinSize< ::zx::socket>();
// Must have enough bytes for input.
if (size_ < min_size_) {
xprintf("Early exit: Input size too small: %zu < %zu\n", size_,
min_size_);
return 0;
}
const size_t slack_size_ = size_ - min_size_;
const size_t slack_size_per_param = slack_size_ / 1;
xprintf("Allocating parameters with %zu bytes (%zu bytes each)\n",
slack_size_, slack_size_per_param);
size_t param_size_;
param_size_ = MinSize< ::zx::socket>() + slack_size_per_param;
xprintf("Allocating %zu bytes for ::zx::socket a\n", param_size_);
::zx::socket a = Allocate< ::zx::socket>{}(&src_, &param_size_);
xprintf("Invoking method test_name_ChannelProtocol.MutateSocket\n");
protocol_->MutateSocket(
std::move(a),
[signaller = fuzzer_.NewCallbackSignaller()](::zx::socket b) {
xprintf("Invoked test_name_ChannelProtocol.MutateSocket\n");
zx_status_t status_ = signaller.SignalCallback();
if (status_ != ZX_OK) {
xprintf("signaller.SignalCallback returned bad status: %d\n",
status_);
}
});
#endif
}
loop_->RunUntilIdle();
if ((status_ = fuzzer_.WaitForCallback()) != ZX_OK) {
xprintf("fuzzer.WaitForCallback returned bad status: %d\n", status_);
}
protocol_.Unbind();
#endif
}
if (protocol_selection_ == 1) {
#if !defined(PROTOCOL_test_name_WithAndWithoutRequestResponse)
// Selected protocol from FIDL file that is not part of this fuzzer.
xprintf(
"Early exit: Chose disabled protocol: "
"test_name_WithAndWithoutRequestResponse\n");
return 0;
#else
::fidl::InterfacePtr< ::test::name::WithAndWithoutRequestResponse>
protocol_;
xprintf("Starting test_name_WithAndWithoutRequestResponse service\n");
::fidl::fuzzing::Fuzzer< ::test::name::WithAndWithoutRequestResponse>
fuzzer_(loop_->dispatcher());
if ((status_ = fuzzer_.Init()) != ZX_OK) {
xprintf("Early exit: fuzzer.Init returned bad status: %d\n", status_);
return 0;
}
if ((status_ = fuzzer_.BindService()) != ZX_OK) {
xprintf("Early exit: fuzzer.BindService returned bad status: %d\n",
status_);
return 0;
}
if ((status_ = fuzzer_.BindClient(&protocol_, loop_->dispatcher())) !=
ZX_OK) {
xprintf("Early exit: fuzzer.BindClient returned bad status: %d\n",
status_);
return 0;
}
FuzzInput src_(data_, size_);
uint8_t method_selector_ = data_[1];
uint8_t method_selection_ = method_selector_ % 8;
if (method_selection_ == 0) {
#if !(ALL_METHODS || defined(METHOD_NoRequestNoResponse))
// Selected method from protocol that is not part of this fuzzer.
xprintf("Early exit: Chose disabled method: NoRequestNoResponse\n");
return 0;
#else
const size_t min_size_ = ;
// Must have enough bytes for input.
if (size_ < min_size_) {
xprintf("Early exit: Input size too small: %zu < %zu\n", size_,
min_size_);
return 0;
}
const size_t slack_size_ = size_ - min_size_;
const size_t slack_size_per_param = slack_size_ / 0;
xprintf("Allocating parameters with %zu bytes (%zu bytes each)\n",
slack_size_, slack_size_per_param);
size_t param_size_;
xprintf(
"Invoking method "
"test_name_WithAndWithoutRequestResponse.NoRequestNoResponse\n");
protocol_->NoRequestNoResponse();
#endif
}
if (method_selection_ == 1) {
#if !(ALL_METHODS || defined(METHOD_NoRequestEmptyResponse))
// Selected method from protocol that is not part of this fuzzer.
xprintf("Early exit: Chose disabled method: NoRequestEmptyResponse\n");
return 0;
#else
const size_t min_size_ = ;
// Must have enough bytes for input.
if (size_ < min_size_) {
xprintf("Early exit: Input size too small: %zu < %zu\n", size_,
min_size_);
return 0;
}
const size_t slack_size_ = size_ - min_size_;
const size_t slack_size_per_param = slack_size_ / 0;
xprintf("Allocating parameters with %zu bytes (%zu bytes each)\n",
slack_size_, slack_size_per_param);
size_t param_size_;
xprintf(
"Invoking method "
"test_name_WithAndWithoutRequestResponse.NoRequestEmptyResponse\n");
protocol_->NoRequestEmptyResponse();
#endif
}
if (method_selection_ == 2) {
#if !(ALL_METHODS || defined(METHOD_NoRequestWithResponse))
// Selected method from protocol that is not part of this fuzzer.
xprintf("Early exit: Chose disabled method: NoRequestWithResponse\n");
return 0;
#else
const size_t min_size_ = ;
// Must have enough bytes for input.
if (size_ < min_size_) {
xprintf("Early exit: Input size too small: %zu < %zu\n", size_,
min_size_);
return 0;
}
const size_t slack_size_ = size_ - min_size_;
const size_t slack_size_per_param = slack_size_ / 0;
xprintf("Allocating parameters with %zu bytes (%zu bytes each)\n",
slack_size_, slack_size_per_param);
size_t param_size_;
xprintf(
"Invoking method "
"test_name_WithAndWithoutRequestResponse.NoRequestWithResponse\n");
protocol_->NoRequestWithResponse([signaller =
fuzzer_.NewCallbackSignaller()](
::std::string ret) {
xprintf(
"Invoked "
"test_name_WithAndWithoutRequestResponse.NoRequestWithResponse\n");
zx_status_t status_ = signaller.SignalCallback();
if (status_ != ZX_OK) {
xprintf("signaller.SignalCallback returned bad status: %d\n",
status_);
}
});
#endif
}
if (method_selection_ == 3) {
#if !(ALL_METHODS || defined(METHOD_WithRequestNoResponse))
// Selected method from protocol that is not part of this fuzzer.
xprintf("Early exit: Chose disabled method: WithRequestNoResponse\n");
return 0;
#else
const size_t min_size_ = MinSize< ::std::string>();
// Must have enough bytes for input.
if (size_ < min_size_) {
xprintf("Early exit: Input size too small: %zu < %zu\n", size_,
min_size_);
return 0;
}
const size_t slack_size_ = size_ - min_size_;
const size_t slack_size_per_param = slack_size_ / 1;
xprintf("Allocating parameters with %zu bytes (%zu bytes each)\n",
slack_size_, slack_size_per_param);
size_t param_size_;
param_size_ = MinSize< ::std::string>() + slack_size_per_param;
xprintf("Allocating %zu bytes for ::std::string arg\n", param_size_);
::std::string arg = Allocate< ::std::string>{}(&src_, &param_size_);
xprintf(
"Invoking method "
"test_name_WithAndWithoutRequestResponse.WithRequestNoResponse\n");
protocol_->WithRequestNoResponse(std::move(arg));
#endif
}
if (method_selection_ == 4) {
#if !(ALL_METHODS || defined(METHOD_WithRequestEmptyResponse))
// Selected method from protocol that is not part of this fuzzer.
xprintf("Early exit: Chose disabled method: WithRequestEmptyResponse\n");
return 0;
#else
const size_t min_size_ = MinSize< ::std::string>();
// Must have enough bytes for input.
if (size_ < min_size_) {
xprintf("Early exit: Input size too small: %zu < %zu\n", size_,
min_size_);
return 0;
}
const size_t slack_size_ = size_ - min_size_;
const size_t slack_size_per_param = slack_size_ / 1;
xprintf("Allocating parameters with %zu bytes (%zu bytes each)\n",
slack_size_, slack_size_per_param);
size_t param_size_;
param_size_ = MinSize< ::std::string>() + slack_size_per_param;
xprintf("Allocating %zu bytes for ::std::string arg\n", param_size_);
::std::string arg = Allocate< ::std::string>{}(&src_, &param_size_);
xprintf(
"Invoking method "
"test_name_WithAndWithoutRequestResponse.WithRequestEmptyResponse\n");
protocol_->WithRequestEmptyResponse(std::move(arg));
#endif
}
if (method_selection_ == 5) {
#if !(ALL_METHODS || defined(METHOD_WithRequestWithResponse))
// Selected method from protocol that is not part of this fuzzer.
xprintf("Early exit: Chose disabled method: WithRequestWithResponse\n");
return 0;
#else
const size_t min_size_ = MinSize< ::std::string>();
// Must have enough bytes for input.
if (size_ < min_size_) {
xprintf("Early exit: Input size too small: %zu < %zu\n", size_,
min_size_);
return 0;
}
const size_t slack_size_ = size_ - min_size_;
const size_t slack_size_per_param = slack_size_ / 1;
xprintf("Allocating parameters with %zu bytes (%zu bytes each)\n",
slack_size_, slack_size_per_param);
size_t param_size_;
param_size_ = MinSize< ::std::string>() + slack_size_per_param;
xprintf("Allocating %zu bytes for ::std::string arg\n", param_size_);
::std::string arg = Allocate< ::std::string>{}(&src_, &param_size_);
xprintf(
"Invoking method "
"test_name_WithAndWithoutRequestResponse.WithRequestWithResponse\n");
protocol_->WithRequestWithResponse(
std::move(arg),
[signaller = fuzzer_.NewCallbackSignaller()](::std::string ret) {
xprintf(
"Invoked "
"test_name_WithAndWithoutRequestResponse."
"WithRequestWithResponse\n");
zx_status_t status_ = signaller.SignalCallback();
if (status_ != ZX_OK) {
xprintf("signaller.SignalCallback returned bad status: %d\n",
status_);
}
});
#endif
}
if (method_selection_ == 6) {
#if !(ALL_METHODS || defined(METHOD_OnEmptyResponse))
// Selected method from protocol that is not part of this fuzzer.
xprintf("Early exit: Chose disabled method: OnEmptyResponse\n");
return 0;
#else
const size_t min_size_ = ;
// Must have enough bytes for input.
if (size_ < min_size_) {
xprintf("Early exit: Input size too small: %zu < %zu\n", size_,
min_size_);
return 0;
}
const size_t slack_size_ = size_ - min_size_;
const size_t slack_size_per_param = slack_size_ / 0;
xprintf("Allocating parameters with %zu bytes (%zu bytes each)\n",
slack_size_, slack_size_per_param);
size_t param_size_;
xprintf(
"Invoking method "
"test_name_WithAndWithoutRequestResponse.OnEmptyResponse\n");
protocol_->OnEmptyResponse();
#endif
}
if (method_selection_ == 7) {
#if !(ALL_METHODS || defined(METHOD_OnWithResponse))
// Selected method from protocol that is not part of this fuzzer.
xprintf("Early exit: Chose disabled method: OnWithResponse\n");
return 0;
#else
const size_t min_size_ = ;
// Must have enough bytes for input.
if (size_ < min_size_) {
xprintf("Early exit: Input size too small: %zu < %zu\n", size_,
min_size_);
return 0;
}
const size_t slack_size_ = size_ - min_size_;
const size_t slack_size_per_param = slack_size_ / 0;
xprintf("Allocating parameters with %zu bytes (%zu bytes each)\n",
slack_size_, slack_size_per_param);
size_t param_size_;
xprintf(
"Invoking method "
"test_name_WithAndWithoutRequestResponse.OnWithResponse\n");
protocol_->OnWithResponse([signaller = fuzzer_.NewCallbackSignaller()](
::std::string ret) {
xprintf(
"Invoked test_name_WithAndWithoutRequestResponse.OnWithResponse\n");
zx_status_t status_ = signaller.SignalCallback();
if (status_ != ZX_OK) {
xprintf("signaller.SignalCallback returned bad status: %d\n",
status_);
}
});
#endif
}
loop_->RunUntilIdle();
if ((status_ = fuzzer_.WaitForCallback()) != ZX_OK) {
xprintf("fuzzer.WaitForCallback returned bad status: %d\n", status_);
}
protocol_.Unbind();
#endif
}
if (protocol_selection_ == 2) {
#if !defined(PROTOCOL_test_name_WithErrorSyntax)
// Selected protocol from FIDL file that is not part of this fuzzer.
xprintf("Early exit: Chose disabled protocol: test_name_WithErrorSyntax\n");
return 0;
#else
::fidl::InterfacePtr< ::test::name::WithErrorSyntax> protocol_;
xprintf("Starting test_name_WithErrorSyntax service\n");
::fidl::fuzzing::Fuzzer< ::test::name::WithErrorSyntax> fuzzer_(
loop_->dispatcher());
if ((status_ = fuzzer_.Init()) != ZX_OK) {
xprintf("Early exit: fuzzer.Init returned bad status: %d\n", status_);
return 0;
}
if ((status_ = fuzzer_.BindService()) != ZX_OK) {
xprintf("Early exit: fuzzer.BindService returned bad status: %d\n",
status_);
return 0;
}
if ((status_ = fuzzer_.BindClient(&protocol_, loop_->dispatcher())) !=
ZX_OK) {
xprintf("Early exit: fuzzer.BindClient returned bad status: %d\n",
status_);
return 0;
}
FuzzInput src_(data_, size_);
uint8_t method_selector_ = data_[1];
uint8_t method_selection_ = method_selector_ % 3;
if (method_selection_ == 0) {
#if !(ALL_METHODS || defined(METHOD_ResponseAsStruct))
// Selected method from protocol that is not part of this fuzzer.
xprintf("Early exit: Chose disabled method: ResponseAsStruct\n");
return 0;
#else
const size_t min_size_ = ;
// Must have enough bytes for input.
if (size_ < min_size_) {
xprintf("Early exit: Input size too small: %zu < %zu\n", size_,
min_size_);
return 0;
}
const size_t slack_size_ = size_ - min_size_;
const size_t slack_size_per_param = slack_size_ / 0;
xprintf("Allocating parameters with %zu bytes (%zu bytes each)\n",
slack_size_, slack_size_per_param);
size_t param_size_;
xprintf("Invoking method test_name_WithErrorSyntax.ResponseAsStruct\n");
protocol_->ResponseAsStruct(
[signaller = fuzzer_.NewCallbackSignaller()](
WithErrorSyntax_ResponseAsStruct_Result result) {
xprintf("Invoked test_name_WithErrorSyntax.ResponseAsStruct\n");
zx_status_t status_ = signaller.SignalCallback();
if (status_ != ZX_OK) {
xprintf("signaller.SignalCallback returned bad status: %d\n",
status_);
}
});
#endif
}
if (method_selection_ == 1) {
#if !(ALL_METHODS || defined(METHOD_ErrorAsPrimitive))
// Selected method from protocol that is not part of this fuzzer.
xprintf("Early exit: Chose disabled method: ErrorAsPrimitive\n");
return 0;
#else
const size_t min_size_ = ;
// Must have enough bytes for input.
if (size_ < min_size_) {
xprintf("Early exit: Input size too small: %zu < %zu\n", size_,
min_size_);
return 0;
}
const size_t slack_size_ = size_ - min_size_;
const size_t slack_size_per_param = slack_size_ / 0;
xprintf("Allocating parameters with %zu bytes (%zu bytes each)\n",
slack_size_, slack_size_per_param);
size_t param_size_;
xprintf("Invoking method test_name_WithErrorSyntax.ErrorAsPrimitive\n");
protocol_->ErrorAsPrimitive(
[signaller = fuzzer_.NewCallbackSignaller()](
WithErrorSyntax_ErrorAsPrimitive_Result result) {
xprintf("Invoked test_name_WithErrorSyntax.ErrorAsPrimitive\n");
zx_status_t status_ = signaller.SignalCallback();
if (status_ != ZX_OK) {
xprintf("signaller.SignalCallback returned bad status: %d\n",
status_);
}
});
#endif
}
if (method_selection_ == 2) {
#if !(ALL_METHODS || defined(METHOD_ErrorAsEnum))
// Selected method from protocol that is not part of this fuzzer.
xprintf("Early exit: Chose disabled method: ErrorAsEnum\n");
return 0;
#else
const size_t min_size_ = ;
// Must have enough bytes for input.
if (size_ < min_size_) {
xprintf("Early exit: Input size too small: %zu < %zu\n", size_,
min_size_);
return 0;
}
const size_t slack_size_ = size_ - min_size_;
const size_t slack_size_per_param = slack_size_ / 0;
xprintf("Allocating parameters with %zu bytes (%zu bytes each)\n",
slack_size_, slack_size_per_param);
size_t param_size_;
xprintf("Invoking method test_name_WithErrorSyntax.ErrorAsEnum\n");
protocol_->ErrorAsEnum([signaller = fuzzer_.NewCallbackSignaller()](
WithErrorSyntax_ErrorAsEnum_Result result) {
xprintf("Invoked test_name_WithErrorSyntax.ErrorAsEnum\n");
zx_status_t status_ = signaller.SignalCallback();
if (status_ != ZX_OK) {
xprintf("signaller.SignalCallback returned bad status: %d\n",
status_);
}
});
#endif
}
loop_->RunUntilIdle();
if ((status_ = fuzzer_.WaitForCallback()) != ZX_OK) {
xprintf("fuzzer.WaitForCallback returned bad status: %d\n", status_);
}
protocol_.Unbind();
#endif
}
xprintf("Fuzzer stopped!\n");
return 0;
}