From b690bd011fac0d3a7a6fc57a34b2e449cb24c759 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Thu, 11 Nov 2021 14:33:17 -0800 Subject: [PATCH] Allow API fuzzer to send multiple slices (#27993) * Allow API fuzzer to send multiple slices * fixes --- src/core/lib/transport/byte_stream.cc | 4 ++++ test/core/end2end/fuzzers/api_fuzzer.cc | 7 +++++-- test/core/end2end/fuzzers/api_fuzzer.proto | 2 +- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/core/lib/transport/byte_stream.cc b/src/core/lib/transport/byte_stream.cc index 3cc5275e51d..8d3b22bd26e 100644 --- a/src/core/lib/transport/byte_stream.cc +++ b/src/core/lib/transport/byte_stream.cc @@ -40,6 +40,10 @@ SliceBufferByteStream::SliceBufferByteStream(grpc_slice_buffer* slice_buffer, GPR_ASSERT(slice_buffer->length <= UINT32_MAX); grpc_slice_buffer_init(&backing_buffer_); grpc_slice_buffer_swap(slice_buffer, &backing_buffer_); + if (backing_buffer_.count == 0) { + grpc_slice_buffer_add_indexed(&backing_buffer_, grpc_empty_slice()); + GPR_ASSERT(backing_buffer_.count > 0); + } } SliceBufferByteStream::~SliceBufferByteStream() {} diff --git a/test/core/end2end/fuzzers/api_fuzzer.cc b/test/core/end2end/fuzzers/api_fuzzer.cc index e231c01a505..c8cb41fb6c8 100644 --- a/test/core/end2end/fuzzers/api_fuzzer.cc +++ b/test/core/end2end/fuzzers/api_fuzzer.cc @@ -379,9 +379,12 @@ class Call : public std::enable_shared_from_this { *batch_is_ok = false; } else { *batch_ops |= 1 << GRPC_OP_SEND_MESSAGE; - auto send = ReadSlice(batch_op.send_message().message()); + std::vector slices; + for (const auto& m : batch_op.send_message().message()) { + slices.push_back(ReadSlice(m)); + } send_message_ = op.data.send_message.send_message = - grpc_raw_byte_buffer_create(&send, 1); + grpc_raw_byte_buffer_create(slices.data(), slices.size()); unwinders->push_back([this]() { grpc_byte_buffer_destroy(send_message_); send_message_ = nullptr; diff --git a/test/core/end2end/fuzzers/api_fuzzer.proto b/test/core/end2end/fuzzers/api_fuzzer.proto index 84968b90ed3..b546d93f96d 100644 --- a/test/core/end2end/fuzzers/api_fuzzer.proto +++ b/test/core/end2end/fuzzers/api_fuzzer.proto @@ -110,7 +110,7 @@ message SendInitialMetadata { } message SendMessage { - ByteSlice message = 1; + repeated ByteSlice message = 1; } message SendCloseFromClient {