transport/binder/end2end/fuzzers/client_fuzzer.cc
Go to the documentation of this file.
1 // Copyright 2021 gRPC authors.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #include <thread>
16 #include <utility>
17 
18 #include "absl/memory/memory.h"
19 
20 #include <grpc/grpc.h>
22 
27 #include "src/libfuzzer/libfuzzer_macro.h"
28 #include "test/core/transport/binder/end2end/fuzzers/binder_transport_fuzzer.pb.h"
30 
31 bool squelch = true;
32 bool leak_check = true;
33 
34 static void* tag(intptr_t t) { return reinterpret_cast<void*>(t); }
35 
36 static void dont_log(gpr_log_func_args*) {}
37 
38 DEFINE_PROTO_FUZZER(const binder_transport_fuzzer::Input& input) {
41  grpc_init();
42  {
43  // Copied and modified from grpc/test/core/end2end/fuzzers/client_fuzzer.cc
46 
49  absl::make_unique<grpc_binder::fuzzing::BinderForFuzzing>(
50  input.incoming_parcels()),
51  std::make_shared<
54  const_cast<char*>(GRPC_ARG_DEFAULT_AUTHORITY),
55  const_cast<char*>("test-authority"));
57  grpc_channel_args_copy_and_add(nullptr, &authority_arg, 1);
58  auto channel_args = grpc_core::CoreConfiguration::Get()
61  auto channel =
62  grpc_core::Channel::Create("test-target", channel_args,
63  GRPC_CLIENT_DIRECT_CHANNEL, client_transport)
64  ->release()
65  ->c_ptr();
67  grpc_slice host = grpc_slice_from_static_string("localhost");
69  channel, nullptr, 0, cq, grpc_slice_from_static_string("/foo"), &host,
78 
79  grpc_op ops[6];
80  memset(ops, 0, sizeof(ops));
81  grpc_op* op = ops;
84  op->flags = 0;
85  op->reserved = nullptr;
86  op++;
88  op->flags = 0;
89  op->reserved = nullptr;
90  op++;
94  op->flags = 0;
95  op->reserved = nullptr;
96  op++;
99  op->flags = 0;
100  op->reserved = nullptr;
101  op++;
106  op->flags = 0;
107  op->reserved = nullptr;
108  op++;
110  call, ops, static_cast<size_t>(op - ops), tag(1), nullptr);
111  int requested_calls = 1;
113  grpc_event ev;
114  while (true) {
117  nullptr);
118  switch (ev.type) {
119  case GRPC_QUEUE_TIMEOUT:
120  goto done;
121  case GRPC_QUEUE_SHUTDOWN:
122  break;
123  case GRPC_OP_COMPLETE:
124  requested_calls--;
125  break;
126  }
127  }
128 
129  done:
130  if (requested_calls) {
131  grpc_call_cancel(call, nullptr);
132  }
134  for (int i = 0; i < requested_calls; i++) {
136  nullptr);
138  }
140  for (int i = 0; i < requested_calls; i++) {
142  nullptr);
144  }
151  if (response_payload_recv != nullptr) {
153  }
154  }
155  grpc_shutdown();
156 }
grpc_arg
Definition: grpc_types.h:103
grpc_slice_unref
GPRAPI void grpc_slice_unref(grpc_slice s)
Definition: slice_api.cc:32
grpc_op::flags
uint32_t flags
Definition: grpc_types.h:644
grpc_call_error
grpc_call_error
Definition: grpc_types.h:464
grpc_call_cancel
GRPCAPI grpc_call_error grpc_call_cancel(grpc_call *call, void *reserved)
Definition: call.cc:1782
grpc_op::grpc_op_data::grpc_op_recv_status_on_client::trailing_metadata
grpc_metadata_array * trailing_metadata
Definition: grpc_types.h:701
core_configuration.h
grpc_op::grpc_op_data::grpc_op_recv_status_on_client::status
grpc_status_code * status
Definition: grpc_types.h:702
memset
return memset(p, 0, total)
grpc_binder::fuzzing::JoinFuzzingThread
void JoinFuzzingThread()
Definition: fuzzer_utils.cc:32
grpc_op::grpc_op_data::send_initial_metadata
struct grpc_op::grpc_op_data::grpc_op_send_initial_metadata send_initial_metadata
DEFINE_PROTO_FUZZER
DEFINE_PROTO_FUZZER(const binder_transport_fuzzer::Input &input)
Definition: transport/binder/end2end/fuzzers/client_fuzzer.cc:38
grpc_metadata_array
Definition: grpc_types.h:579
grpc::experimental::binder::UntrustedSecurityPolicy
Definition: binder_security_policy.h:44
GRPC_CLIENT_DIRECT_CHANNEL
@ GRPC_CLIENT_DIRECT_CHANNEL
Definition: channel_stack_type.h:34
grpc_op::reserved
void * reserved
Definition: grpc_types.h:646
error
grpc_error_handle error
Definition: retry_filter.cc:499
grpc_status_code
grpc_status_code
Definition: include/grpc/impl/codegen/status.h:28
GRPC_QUEUE_SHUTDOWN
@ GRPC_QUEUE_SHUTDOWN
Definition: grpc_types.h:554
tag
static void * tag(intptr_t t)
Definition: transport/binder/end2end/fuzzers/client_fuzzer.cc:34
GRPC_OP_COMPLETE
@ GRPC_OP_COMPLETE
Definition: grpc_types.h:558
GRPC_CALL_OK
@ GRPC_CALL_OK
Definition: grpc_types.h:466
status
absl::Status status
Definition: rls.cc:251
gpr_inf_future
GPRAPI gpr_timespec gpr_inf_future(gpr_clock_type type)
Definition: src/core/lib/gpr/time.cc:55
grpc_channel_arg_string_create
grpc_arg grpc_channel_arg_string_create(char *name, char *value)
Definition: channel_args.cc:476
grpc_core::Executor::SetThreadingAll
static void SetThreadingAll(bool enable)
Definition: executor.cc:446
grpc_create_binder_transport_client
grpc_transport * grpc_create_binder_transport_client(std::unique_ptr< grpc_binder::Binder > endpoint_binder, std::shared_ptr< grpc::experimental::binder::SecurityPolicy > security_policy)
Definition: binder_transport.cc:737
grpc_channel_args
Definition: grpc_types.h:132
grpc_op::grpc_op_data::recv_message
struct grpc_op::grpc_op_data::grpc_op_recv_message recv_message
gpr_log_func_args
Definition: include/grpc/impl/codegen/log.h:77
call
FilterStackCall * call
Definition: call.cc:750
grpc_op::data
union grpc_op::grpc_op_data data
grpc_metadata_array_destroy
GRPCAPI void grpc_metadata_array_destroy(grpc_metadata_array *array)
Definition: metadata_array.cc:35
grpc_op::grpc_op_data::grpc_op_recv_message::recv_message
struct grpc_byte_buffer ** recv_message
Definition: grpc_types.h:693
trailing_metadata_recv
static grpc_metadata_array trailing_metadata_recv
Definition: test/core/fling/client.cc:43
GRPC_ARG_DEFAULT_AUTHORITY
#define GRPC_ARG_DEFAULT_AUTHORITY
Definition: grpc_types.h:251
binder_security_policy.h
channel
wrapped_grpc_channel * channel
Definition: src/php/ext/grpc/call.h:33
grpc_test_only_set_slice_hash_seed
void grpc_test_only_set_slice_hash_seed(uint32_t seed)
Definition: slice_refcount.cc:33
asyncio_get_stats.args
args
Definition: asyncio_get_stats.py:40
GRPC_OP_RECV_INITIAL_METADATA
@ GRPC_OP_RECV_INITIAL_METADATA
Definition: grpc_types.h:617
GPR_ASSERT
#define GPR_ASSERT(x)
Definition: include/grpc/impl/codegen/log.h:94
grpc_core::CoreConfiguration::Get
static const CoreConfiguration & Get()
Definition: core_configuration.h:82
grpc_core::ExecCtx::Flush
bool Flush()
Definition: exec_ctx.cc:69
grpc_call_unref
GRPCAPI void grpc_call_unref(grpc_call *call)
Definition: call.cc:1770
grpc_event
Definition: grpc_types.h:564
grpc_completion_queue
Definition: completion_queue.cc:347
grpc.h
grpc_call
struct grpc_call grpc_call
Definition: grpc_types.h:70
response_payload_recv
static grpc_byte_buffer * response_payload_recv
Definition: test/core/fling/client.cc:44
grpc_byte_buffer
Definition: grpc_types.h:43
done
struct tab * done
Definition: bloaty/third_party/zlib/examples/enough.c:176
grpc_op
Definition: grpc_types.h:640
grpc_channel_args_destroy
void grpc_channel_args_destroy(grpc_channel_args *a)
Definition: channel_args.cc:360
grpc_slice_from_static_string
GPRAPI grpc_slice grpc_slice_from_static_string(const char *source)
Definition: slice/slice.cc:89
grpc_empty_slice
GPRAPI grpc_slice grpc_empty_slice(void)
Definition: slice/slice.cc:42
grpc_slice
Definition: include/grpc/impl/codegen/slice.h:65
fuzzer_utils.h
dont_log
static void dont_log(gpr_log_func_args *)
Definition: transport/binder/end2end/fuzzers/client_fuzzer.cc:36
intptr_t
_W64 signed int intptr_t
Definition: stdint-msvc2008.h:118
grpc_core::CoreConfiguration::channel_args_preconditioning
const ChannelArgsPreconditioning & channel_args_preconditioning() const
Definition: core_configuration.h:139
grpc_core::ExecCtx
Definition: exec_ctx.h:97
executor.h
grpc_op::op
grpc_op_type op
Definition: grpc_types.h:642
grpc_op::grpc_op_data::grpc_op_send_initial_metadata::count
size_t count
Definition: grpc_types.h:653
grpc_op::grpc_op_data::grpc_op_recv_status_on_client::status_details
grpc_slice * status_details
Definition: grpc_types.h:703
details
static grpc_slice details
Definition: test/core/fling/client.cc:46
grpc_channel_create_call
GRPCAPI grpc_call * grpc_channel_create_call(grpc_channel *channel, grpc_call *parent_call, uint32_t propagation_mask, grpc_completion_queue *completion_queue, grpc_slice method, const grpc_slice *host, gpr_timespec deadline, void *reserved)
Definition: channel.cc:311
gpr_inf_past
GPRAPI gpr_timespec gpr_inf_past(gpr_clock_type type)
Definition: src/core/lib/gpr/time.cc:63
GRPC_OP_RECV_MESSAGE
@ GRPC_OP_RECV_MESSAGE
Definition: grpc_types.h:621
leak_check
bool leak_check
Definition: transport/binder/end2end/fuzzers/client_fuzzer.cc:32
grpc_completion_queue_destroy
GRPCAPI void grpc_completion_queue_destroy(grpc_completion_queue *cq)
Definition: completion_queue.cc:1424
GRPC_OP_SEND_INITIAL_METADATA
@ GRPC_OP_SEND_INITIAL_METADATA
Definition: grpc_types.h:598
exec_ctx
grpc_core::ExecCtx exec_ctx
Definition: end2end_binder_transport_test.cc:75
squelch
bool squelch
Definition: transport/binder/end2end/fuzzers/client_fuzzer.cc:31
grpc_op::grpc_op_data::recv_status_on_client
struct grpc_op::grpc_op_data::grpc_op_recv_status_on_client recv_status_on_client
grpc_byte_buffer_destroy
GRPCAPI void grpc_byte_buffer_destroy(grpc_byte_buffer *bb)
Definition: byte_buffer.cc:81
grpc_completion_queue_next
GRPCAPI grpc_event grpc_completion_queue_next(grpc_completion_queue *cq, gpr_timespec deadline, void *reserved)
Definition: completion_queue.cc:1133
grpc_completion_queue_shutdown
GRPCAPI void grpc_completion_queue_shutdown(grpc_completion_queue *cq)
Definition: completion_queue.cc:1416
grpc_channel_destroy
GRPCAPI void grpc_channel_destroy(grpc_channel *channel)
Definition: channel.cc:437
grpc_transport
Definition: transport_impl.h:89
input
std::string input
Definition: bloaty/third_party/protobuf/src/google/protobuf/io/tokenizer_unittest.cc:197
grpc_completion_queue_create_for_next
GRPCAPI grpc_completion_queue * grpc_completion_queue_create_for_next(void *reserved)
Definition: completion_queue_factory.cc:62
grpc_op::grpc_op_data::recv_initial_metadata
struct grpc_op::grpc_op_data::grpc_op_recv_initial_metadata recv_initial_metadata
grpc_event::type
grpc_completion_type type
Definition: grpc_types.h:566
gpr_set_log_function
GPRAPI void gpr_set_log_function(gpr_log_func func)
Definition: log.cc:143
grpc_init
GRPCAPI void grpc_init(void)
Definition: init.cc:146
GRPC_OP_RECV_STATUS_ON_CLIENT
@ GRPC_OP_RECV_STATUS_ON_CLIENT
Definition: grpc_types.h:627
grpc_op::grpc_op_data::grpc_op_recv_initial_metadata::recv_initial_metadata
grpc_metadata_array * recv_initial_metadata
Definition: grpc_types.h:685
GPR_CLOCK_REALTIME
@ GPR_CLOCK_REALTIME
Definition: gpr_types.h:39
op
static grpc_op * op
Definition: test/core/fling/client.cc:47
ops
static grpc_op ops[6]
Definition: test/core/fling/client.cc:39
initial_metadata_recv
static grpc_metadata_array initial_metadata_recv
Definition: test/core/fling/client.cc:42
GRPC_QUEUE_TIMEOUT
@ GRPC_QUEUE_TIMEOUT
Definition: grpc_types.h:556
grpc_call_start_batch
GRPCAPI grpc_call_error grpc_call_start_batch(grpc_call *call, const grpc_op *ops, size_t nops, void *tag, void *reserved)
Definition: call.cc:1831
grpc_shutdown
GRPCAPI void grpc_shutdown(void)
Definition: init.cc:209
grpc_core::ChannelArgsPreconditioning::PreconditionChannelArgs
ChannelArgs PreconditionChannelArgs(const grpc_channel_args *args) const
Definition: channel_args_preconditioning.cc:34
grpc_core::Channel::Create
static absl::StatusOr< RefCountedPtr< Channel > > Create(const char *target, ChannelArgs args, grpc_channel_stack_type channel_stack_type, grpc_transport *optional_transport)
Definition: channel.cc:202
cq
static grpc_completion_queue * cq
Definition: test/core/fling/client.cc:37
grpc_core::ExecCtx::Get
static ExecCtx * Get()
Definition: exec_ctx.h:205
grpc_channel_args_copy_and_add
grpc_channel_args * grpc_channel_args_copy_and_add(const grpc_channel_args *src, const grpc_arg *to_add, size_t num_to_add)
Definition: channel_args.cc:224
GRPC_OP_SEND_CLOSE_FROM_CLIENT
@ GRPC_OP_SEND_CLOSE_FROM_CLIENT
Definition: grpc_types.h:607
i
uint64_t i
Definition: abseil-cpp/absl/container/btree_benchmark.cc:230
grpc_metadata_array_init
GRPCAPI void grpc_metadata_array_init(grpc_metadata_array *array)
Definition: metadata_array.cc:30
binder_transport.h
channel.h


grpc
Author(s):
autogenerated on Fri May 16 2025 02:57:55