end2end/fuzzers/client_fuzzer.cc
Go to the documentation of this file.
1 /*
2  *
3  * Copyright 2016 gRPC authors.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  */
18 
19 #include <string.h>
20 
21 #include <grpc/grpc.h>
22 #include <grpc/support/alloc.h>
24 
31 
32 bool squelch = true;
33 bool leak_check = true;
34 
35 static void discard_write(grpc_slice /*slice*/) {}
36 
37 static void* tag(intptr_t t) { return reinterpret_cast<void*>(t); }
38 
39 static void dont_log(gpr_log_func_args* /*args*/) {}
40 
41 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
44  grpc_init();
45  {
48 
50  grpc_resource_quota_create("context_list_test");
55  .PreconditionChannelArgs(nullptr)
56  .ToC();
61  grpc_chttp2_transport_start_reading(transport, nullptr, nullptr, nullptr);
62  auto channel_args =
65  .PreconditionChannelArgs(nullptr)
66  .SetIfUnset(GRPC_ARG_DEFAULT_AUTHORITY, "test-authority");
68  "test-target", channel_args, GRPC_CLIENT_DIRECT_CHANNEL, transport);
69  grpc_slice host = grpc_slice_from_static_string("localhost");
70  grpc_call* call =
71  grpc_channel_create_call(channel->get()->c_ptr(), nullptr, 0, cq,
72  grpc_slice_from_static_string("/foo"), &host,
74 
82 
83  grpc_op ops[6];
84  memset(ops, 0, sizeof(ops));
85  grpc_op* op = ops;
88  op->flags = 0;
89  op->reserved = nullptr;
90  op++;
92  op->flags = 0;
93  op->reserved = nullptr;
94  op++;
98  op->flags = 0;
99  op->reserved = nullptr;
100  op++;
103  op->flags = 0;
104  op->reserved = nullptr;
105  op++;
110  op->flags = 0;
111  op->reserved = nullptr;
112  op++;
114  grpc_call_start_batch(call, ops, (size_t)(op - ops), tag(1), nullptr);
115  int requested_calls = 1;
117 
120 
121  grpc_event ev;
122  while (true) {
125  nullptr);
126  switch (ev.type) {
127  case GRPC_QUEUE_TIMEOUT:
128  goto done;
129  case GRPC_QUEUE_SHUTDOWN:
130  break;
131  case GRPC_OP_COMPLETE:
132  requested_calls--;
133  break;
134  }
135  }
136 
137  done:
138  if (requested_calls) {
139  grpc_call_cancel(call, nullptr);
140  }
141  for (int i = 0; i < requested_calls; i++) {
143  nullptr);
145  }
147  for (int i = 0; i < requested_calls; i++) {
149  nullptr);
151  }
157  if (response_payload_recv != nullptr) {
159  }
160  }
161  grpc_shutdown();
162  return 0;
163 }
grpc_mock_endpoint_put_read
void grpc_mock_endpoint_put_read(grpc_endpoint *ep, grpc_slice slice)
Definition: mock_endpoint.cc:128
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
mock_endpoint
Definition: mock_endpoint.cc:32
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
grpc_op::grpc_op_data::grpc_op_recv_status_on_client::status
grpc_status_code * status
Definition: grpc_types.h:702
LLVMFuzzerTestOneInput
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
Definition: end2end/fuzzers/client_fuzzer.cc:41
memset
return memset(p, 0, total)
grpc_resource_quota
struct grpc_resource_quota grpc_resource_quota
Definition: grpc_types.h:729
grpc_op::grpc_op_data::send_initial_metadata
struct grpc_op::grpc_op_data::grpc_op_send_initial_metadata send_initial_metadata
grpc_create_chttp2_transport
grpc_transport * grpc_create_chttp2_transport(const grpc_channel_args *channel_args, grpc_endpoint *ep, bool is_client)
Definition: chttp2_transport.cc:3122
grpc_metadata_array
Definition: grpc_types.h:579
GRPC_CLIENT_DIRECT_CHANNEL
@ GRPC_CLIENT_DIRECT_CHANNEL
Definition: channel_stack_type.h:34
grpc_op::reserved
void * reserved
Definition: grpc_types.h:646
string.h
discard_write
static void discard_write(grpc_slice)
Definition: end2end/fuzzers/client_fuzzer.cc:35
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
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_resource_quota_create
GRPCAPI grpc_resource_quota * grpc_resource_quota_create(const char *trace_name)
Definition: api.cc:66
grpc_core::Executor::SetThreadingAll
static void SetThreadingAll(bool enable)
Definition: executor.cc:446
grpc_core::ChannelArgs::SetIfUnset
GRPC_MUST_USE_RESULT ChannelArgs SetIfUnset(absl::string_view name, T value)
Definition: channel_args.h:205
uint8_t
unsigned char uint8_t
Definition: stdint-msvc2008.h:78
grpc_channel_args
Definition: grpc_types.h:132
resource_quota
ResourceQuotaRefPtr resource_quota
Definition: filter_fuzzer.cc:145
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
tag
static void * tag(intptr_t t)
Definition: end2end/fuzzers/client_fuzzer.cc:37
grpc_op::grpc_op_data::grpc_op_recv_message::recv_message
struct grpc_byte_buffer ** recv_message
Definition: grpc_types.h:693
string_util.h
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
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
squelch
bool squelch
Definition: end2end/fuzzers/client_fuzzer.cc:32
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
transport
grpc_transport transport
Definition: filter_fuzzer.cc:146
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_core::ChannelArgs::ToC
const grpc_channel_args * ToC() const
Definition: channel_args.cc:94
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
intptr_t
_W64 signed int intptr_t
Definition: stdint-msvc2008.h:118
data
char data[kBufferLength]
Definition: abseil-cpp/absl/strings/internal/str_format/float_conversion.cc:1006
slice_internal.h
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
grpc_slice_from_copied_buffer
GPRAPI grpc_slice grpc_slice_from_copied_buffer(const char *source, size_t len)
Definition: slice/slice.cc:170
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
grpc_resource_quota_unref
GRPCAPI void grpc_resource_quota_unref(grpc_resource_quota *resource_quota)
Definition: api.cc:79
mock_endpoint.h
alloc.h
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
chttp2_transport.h
dont_log
static void dont_log(gpr_log_func_args *)
Definition: end2end/fuzzers/client_fuzzer.cc:39
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_transport
Definition: transport_impl.h:89
grpc_mock_endpoint_create
grpc_endpoint * grpc_mock_endpoint_create(void(*on_write)(grpc_slice slice))
Definition: mock_endpoint.cc:118
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
leak_check
bool leak_check
Definition: end2end/fuzzers/client_fuzzer.cc:33
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
size
voidpf void uLong size
Definition: bloaty/third_party/zlib/contrib/minizip/ioapi.h:136
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_endpoint
Definition: endpoint.h:105
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_chttp2_transport_start_reading
void grpc_chttp2_transport_start_reading(grpc_transport *transport, grpc_slice_buffer *read_buffer, grpc_closure *notify_on_receive_settings, grpc_closure *notify_on_close)
Definition: chttp2_transport.cc:3128
grpc_core::ExecCtx::Get
static ExecCtx * Get()
Definition: exec_ctx.h:205
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
api.h
channel.h


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