blob: b24e867b3a1f3ddb73bdf697ce907e7a54722bd2 [file] [log] [blame]
// WARNING: This file is machine generated by fidlgen.
// fidl_experiment = output_index_json
#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/protocolpayloads/cpp/libfuzzer.h>
#include <zircon/errors.h>
#include <zircon/syscalls.h>
#include <zircon/types.h>
using namespace ::fuzzing;
using namespace ::test::protocolpayloads;
// 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_ % 1;
xprintf("Starting fuzzer with %zu bytes of data\n", size_);
// Hardcode mutually-exclusive if blocks that selects exactly one protocol.
[[maybe_unused]] zx_status_t status_;
if (protocol_selection_ == 0) {
#if !(defined(GOLDEN_FUZZER) || defined(PROTOCOL_test_protocolpayloads_MainProtocol))
// Selected protocol from FIDL file that is not part of this fuzzer.
xprintf("Early exit: Chose disabled protocol: test_protocolpayloads_MainProtocol\n");
return 0;
#else
::fidl::InterfacePtr< ::test::protocolpayloads::MainProtocol> protocol_;
xprintf("Starting test_protocolpayloads_MainProtocol service\n");
::fidl::fuzzing::Fuzzer< ::test::protocolpayloads::MainProtocol> 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_ % 12;
if (method_selection_ == 0) {
#if !(defined(GOLDEN_FUZZER) || defined(ALL_METHODS) || defined(METHOD_OneWayComposed))
// Selected method from protocol that is not part of this fuzzer.
xprintf("Early exit: Chose disabled method: OneWayComposed\n");
return 0;
#else
const size_t min_size_ = MinSize<int32_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_ / 1;
xprintf("Allocating parameters with %zu bytes (%zu bytes each)\n", slack_size_, slack_size_per_param);
size_t param_size_;
param_size_ = MinSize<int32_t>() + slack_size_per_param;
xprintf("Allocating %zu bytes for int32_t a\n", param_size_);
int32_t a = Allocate<int32_t>{}(&src_, &param_size_);
xprintf("Invoking method test_protocolpayloads_MainProtocol.OneWayComposed\n");
protocol_->OneWayComposed(std::move(a));
#endif
}
if (method_selection_ == 1) {
#if !(defined(GOLDEN_FUZZER) || defined(ALL_METHODS) || defined(METHOD_TwoWayComposed))
// Selected method from protocol that is not part of this fuzzer.
xprintf("Early exit: Chose disabled method: TwoWayComposed\n");
return 0;
#else
const size_t min_size_ = MinSize<int32_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_ / 1;
xprintf("Allocating parameters with %zu bytes (%zu bytes each)\n", slack_size_, slack_size_per_param);
size_t param_size_;
param_size_ = MinSize<int32_t>() + slack_size_per_param;
xprintf("Allocating %zu bytes for int32_t a\n", param_size_);
int32_t a = Allocate<int32_t>{}(&src_, &param_size_);
xprintf("Invoking method test_protocolpayloads_MainProtocol.TwoWayComposed\n");
protocol_->TwoWayComposed(std::move(a), [signaller = fuzzer_.NewCallbackSignaller()](int32_t a) {
xprintf("Invoked test_protocolpayloads_MainProtocol.TwoWayComposed\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 !(defined(GOLDEN_FUZZER) || defined(ALL_METHODS) || defined(METHOD_TwoWayComposedWithError))
// Selected method from protocol that is not part of this fuzzer.
xprintf("Early exit: Chose disabled method: TwoWayComposedWithError\n");
return 0;
#else
const size_t min_size_ = MinSize<int32_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_ / 1;
xprintf("Allocating parameters with %zu bytes (%zu bytes each)\n", slack_size_, slack_size_per_param);
size_t param_size_;
param_size_ = MinSize<int32_t>() + slack_size_per_param;
xprintf("Allocating %zu bytes for int32_t a\n", param_size_);
int32_t a = Allocate<int32_t>{}(&src_, &param_size_);
xprintf("Invoking method test_protocolpayloads_MainProtocol.TwoWayComposedWithError\n");
protocol_->TwoWayComposedWithError(std::move(a), [signaller = fuzzer_.NewCallbackSignaller()](::test::protocolpayloads::imported::ComposedProtocol_TwoWayComposedWithError_Result ComposedProtocol_TwoWayComposedWithError_Result) {
xprintf("Invoked test_protocolpayloads_MainProtocol.TwoWayComposedWithError\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 !(defined(GOLDEN_FUZZER) || defined(ALL_METHODS) || defined(METHOD_OneWayLocal))
// Selected method from protocol that is not part of this fuzzer.
xprintf("Early exit: Chose disabled method: OneWayLocal\n");
return 0;
#else
const size_t min_size_ = MinSize<uint32_t>() + MinSize<uint32_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<uint32_t>() + slack_size_per_param;
xprintf("Allocating %zu bytes for uint32_t a\n", param_size_);
uint32_t a = Allocate<uint32_t>{}(&src_, &param_size_);
param_size_ = MinSize<uint32_t>() + slack_size_per_param;
xprintf("Allocating %zu bytes for uint32_t b\n", param_size_);
uint32_t b = Allocate<uint32_t>{}(&src_, &param_size_);
xprintf("Invoking method test_protocolpayloads_MainProtocol.OneWayLocal\n");
protocol_->OneWayLocal(std::move(a), std::move(b));
#endif
}
if (method_selection_ == 4) {
#if !(defined(GOLDEN_FUZZER) || defined(ALL_METHODS) || defined(METHOD_TwoWayLocal))
// Selected method from protocol that is not part of this fuzzer.
xprintf("Early exit: Chose disabled method: TwoWayLocal\n");
return 0;
#else
const size_t min_size_ = MinSize<uint32_t>() + MinSize<uint32_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<uint32_t>() + slack_size_per_param;
xprintf("Allocating %zu bytes for uint32_t a\n", param_size_);
uint32_t a = Allocate<uint32_t>{}(&src_, &param_size_);
param_size_ = MinSize<uint32_t>() + slack_size_per_param;
xprintf("Allocating %zu bytes for uint32_t b\n", param_size_);
uint32_t b = Allocate<uint32_t>{}(&src_, &param_size_);
xprintf("Invoking method test_protocolpayloads_MainProtocol.TwoWayLocal\n");
protocol_->TwoWayLocal(std::move(a), std::move(b), [signaller = fuzzer_.NewCallbackSignaller()](uint32_t a, uint32_t b) {
xprintf("Invoked test_protocolpayloads_MainProtocol.TwoWayLocal\n");
zx_status_t status_ = signaller.SignalCallback();
if (status_ != ZX_OK) {
xprintf("signaller.SignalCallback returned bad status: %d\n", status_);
}
});
#endif
}
if (method_selection_ == 5) {
#if !(defined(GOLDEN_FUZZER) || defined(ALL_METHODS) || defined(METHOD_TwoWayLocalWithError))
// Selected method from protocol that is not part of this fuzzer.
xprintf("Early exit: Chose disabled method: TwoWayLocalWithError\n");
return 0;
#else
const size_t min_size_ = MinSize<uint32_t>() + MinSize<uint32_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<uint32_t>() + slack_size_per_param;
xprintf("Allocating %zu bytes for uint32_t a\n", param_size_);
uint32_t a = Allocate<uint32_t>{}(&src_, &param_size_);
param_size_ = MinSize<uint32_t>() + slack_size_per_param;
xprintf("Allocating %zu bytes for uint32_t b\n", param_size_);
uint32_t b = Allocate<uint32_t>{}(&src_, &param_size_);
xprintf("Invoking method test_protocolpayloads_MainProtocol.TwoWayLocalWithError\n");
protocol_->TwoWayLocalWithError(std::move(a), std::move(b), [signaller = fuzzer_.NewCallbackSignaller()](::test::protocolpayloads::MainProtocol_TwoWayLocalWithError_Result MainProtocol_TwoWayLocalWithError_Result) {
xprintf("Invoked test_protocolpayloads_MainProtocol.TwoWayLocalWithError\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 !(defined(GOLDEN_FUZZER) || defined(ALL_METHODS) || defined(METHOD_OneWayImport))
// Selected method from protocol that is not part of this fuzzer.
xprintf("Early exit: Chose disabled method: OneWayImport\n");
return 0;
#else
const size_t min_size_ = MinSize<int32_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_ / 1;
xprintf("Allocating parameters with %zu bytes (%zu bytes each)\n", slack_size_, slack_size_per_param);
size_t param_size_;
param_size_ = MinSize<int32_t>() + slack_size_per_param;
xprintf("Allocating %zu bytes for int32_t a\n", param_size_);
int32_t a = Allocate<int32_t>{}(&src_, &param_size_);
xprintf("Invoking method test_protocolpayloads_MainProtocol.OneWayImport\n");
protocol_->OneWayImport(std::move(a));
#endif
}
if (method_selection_ == 7) {
#if !(defined(GOLDEN_FUZZER) || defined(ALL_METHODS) || defined(METHOD_TwoWayImport))
// Selected method from protocol that is not part of this fuzzer.
xprintf("Early exit: Chose disabled method: TwoWayImport\n");
return 0;
#else
const size_t min_size_ = MinSize<int32_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_ / 1;
xprintf("Allocating parameters with %zu bytes (%zu bytes each)\n", slack_size_, slack_size_per_param);
size_t param_size_;
param_size_ = MinSize<int32_t>() + slack_size_per_param;
xprintf("Allocating %zu bytes for int32_t a\n", param_size_);
int32_t a = Allocate<int32_t>{}(&src_, &param_size_);
xprintf("Invoking method test_protocolpayloads_MainProtocol.TwoWayImport\n");
protocol_->TwoWayImport(std::move(a), [signaller = fuzzer_.NewCallbackSignaller()](int32_t a) {
xprintf("Invoked test_protocolpayloads_MainProtocol.TwoWayImport\n");
zx_status_t status_ = signaller.SignalCallback();
if (status_ != ZX_OK) {
xprintf("signaller.SignalCallback returned bad status: %d\n", status_);
}
});
#endif
}
if (method_selection_ == 8) {
#if !(defined(GOLDEN_FUZZER) || defined(ALL_METHODS) || defined(METHOD_TwoWayImportWithError))
// Selected method from protocol that is not part of this fuzzer.
xprintf("Early exit: Chose disabled method: TwoWayImportWithError\n");
return 0;
#else
const size_t min_size_ = MinSize<int32_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_ / 1;
xprintf("Allocating parameters with %zu bytes (%zu bytes each)\n", slack_size_, slack_size_per_param);
size_t param_size_;
param_size_ = MinSize<int32_t>() + slack_size_per_param;
xprintf("Allocating %zu bytes for int32_t a\n", param_size_);
int32_t a = Allocate<int32_t>{}(&src_, &param_size_);
xprintf("Invoking method test_protocolpayloads_MainProtocol.TwoWayImportWithError\n");
protocol_->TwoWayImportWithError(std::move(a), [signaller = fuzzer_.NewCallbackSignaller()](::test::protocolpayloads::MainProtocol_TwoWayImportWithError_Result MainProtocol_TwoWayImportWithError_Result) {
xprintf("Invoked test_protocolpayloads_MainProtocol.TwoWayImportWithError\n");
zx_status_t status_ = signaller.SignalCallback();
if (status_ != ZX_OK) {
xprintf("signaller.SignalCallback returned bad status: %d\n", status_);
}
});
#endif
}
if (method_selection_ == 9) {
#if !(defined(GOLDEN_FUZZER) || defined(ALL_METHODS) || defined(METHOD_OneWayAnon))
// Selected method from protocol that is not part of this fuzzer.
xprintf("Early exit: Chose disabled method: OneWayAnon\n");
return 0;
#else
const size_t min_size_ = MinSize<uint32_t>() + MinSize<uint32_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<uint32_t>() + slack_size_per_param;
xprintf("Allocating %zu bytes for uint32_t a\n", param_size_);
uint32_t a = Allocate<uint32_t>{}(&src_, &param_size_);
param_size_ = MinSize<uint32_t>() + slack_size_per_param;
xprintf("Allocating %zu bytes for uint32_t b\n", param_size_);
uint32_t b = Allocate<uint32_t>{}(&src_, &param_size_);
xprintf("Invoking method test_protocolpayloads_MainProtocol.OneWayAnon\n");
protocol_->OneWayAnon(std::move(a), std::move(b));
#endif
}
if (method_selection_ == 10) {
#if !(defined(GOLDEN_FUZZER) || defined(ALL_METHODS) || defined(METHOD_TwoWayAnon))
// Selected method from protocol that is not part of this fuzzer.
xprintf("Early exit: Chose disabled method: TwoWayAnon\n");
return 0;
#else
const size_t min_size_ = MinSize<uint32_t>() + MinSize<uint32_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<uint32_t>() + slack_size_per_param;
xprintf("Allocating %zu bytes for uint32_t a\n", param_size_);
uint32_t a = Allocate<uint32_t>{}(&src_, &param_size_);
param_size_ = MinSize<uint32_t>() + slack_size_per_param;
xprintf("Allocating %zu bytes for uint32_t b\n", param_size_);
uint32_t b = Allocate<uint32_t>{}(&src_, &param_size_);
xprintf("Invoking method test_protocolpayloads_MainProtocol.TwoWayAnon\n");
protocol_->TwoWayAnon(std::move(a), std::move(b), [signaller = fuzzer_.NewCallbackSignaller()](uint32_t a, uint32_t b) {
xprintf("Invoked test_protocolpayloads_MainProtocol.TwoWayAnon\n");
zx_status_t status_ = signaller.SignalCallback();
if (status_ != ZX_OK) {
xprintf("signaller.SignalCallback returned bad status: %d\n", status_);
}
});
#endif
}
if (method_selection_ == 11) {
#if !(defined(GOLDEN_FUZZER) || defined(ALL_METHODS) || defined(METHOD_TwoWayAnonWithError))
// Selected method from protocol that is not part of this fuzzer.
xprintf("Early exit: Chose disabled method: TwoWayAnonWithError\n");
return 0;
#else
const size_t min_size_ = MinSize<uint32_t>() + MinSize<uint32_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<uint32_t>() + slack_size_per_param;
xprintf("Allocating %zu bytes for uint32_t a\n", param_size_);
uint32_t a = Allocate<uint32_t>{}(&src_, &param_size_);
param_size_ = MinSize<uint32_t>() + slack_size_per_param;
xprintf("Allocating %zu bytes for uint32_t b\n", param_size_);
uint32_t b = Allocate<uint32_t>{}(&src_, &param_size_);
xprintf("Invoking method test_protocolpayloads_MainProtocol.TwoWayAnonWithError\n");
protocol_->TwoWayAnonWithError(std::move(a), std::move(b), [signaller = fuzzer_.NewCallbackSignaller()](::test::protocolpayloads::MainProtocol_TwoWayAnonWithError_Result MainProtocol_TwoWayAnonWithError_Result) {
xprintf("Invoked test_protocolpayloads_MainProtocol.TwoWayAnonWithError\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;
}