Skip to content

Commit

Permalink
diable sso optimize in rpc client buffer, which may cause illegal add…
Browse files Browse the repository at this point in the history
…ress when user return value has std::string_view
  • Loading branch information
poor-circle committed Jul 3, 2024
1 parent 4cd7b82 commit 2566e86
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
11 changes: 9 additions & 2 deletions include/ylt/coro_rpc/impl/coro_rpc_client.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -722,7 +722,7 @@ class coro_rpc_client {
if (!control->has_closed_.compare_exchange_strong(expected, true)) {
return;
}
control->executor_.schedule([control = std::move(control)]() {
control->executor_.schedule([control]() {
asio::error_code ignored_ec;
control->socket_.shutdown(asio::ip::tcp::socket::shutdown_both,
ignored_ec);
Expand Down Expand Up @@ -809,7 +809,14 @@ class coro_rpc_client {
break;
}
uint32_t body_len = header.length;
struct_pack::detail::resize(controller->resp_buffer_.read_buf_, body_len);
struct_pack::detail::resize(
controller->resp_buffer_.read_buf_,
std::max<uint32_t>(body_len, sizeof(std::string)));
if (body_len < sizeof(std::string)) { /* this strange code just disable
any SSO optimize so that rpc result
wont point to illegal address*/
controller->resp_buffer_.read_buf_.resize(body_len);
}
if (header.attach_length == 0) {
ret = co_await coro_io::async_read(
socket,
Expand Down
16 changes: 10 additions & 6 deletions src/coro_rpc/examples/base_examples/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,16 @@ Lazy<void> show_rpc_call() {

// assert(ret.error().code.val() == 404);

ret = co_await client.call<rpc_with_state_by_tag>();
assert(ret.value() == "1");
ret = co_await client.call<rpc_with_state_by_tag>();
assert(ret.value() == "2");
ret = co_await client.call<rpc_with_state_by_tag>();
assert(ret.value() == "3");
auto ret2 = co_await client.call<rpc_with_state_by_tag>();
auto str = ret2.value();
std::cout << ret2.value() << std::endl;
assert(ret2.value() == "1");
ret2 = co_await client.call<rpc_with_state_by_tag>();
std::cout << ret2.value() << std::endl;
assert(ret2.value() == "2");
ret2 = co_await client.call<rpc_with_state_by_tag>();
std::cout << ret2.value() << std::endl;
assert(ret2.value() == "3");
}

int main() {
Expand Down

0 comments on commit 2566e86

Please sign in to comment.