Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions trpc/config/trpc_conf_compatible.cc
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,11 @@ bool TransformConfig(const std::string& from, Json::Value* json_value) {
TRPC_FMT_ERROR("Json parse error. content:{}, error:{}", from, err_msg);
return false;
}
// It will cause coredump if str `from` is not json-format.
if (!json_value->isArray() && !json_value->isObject()) {
TRPC_FMT_ERROR("Json is not array or object. content:{}", from);
return false;
}
} catch (std::exception& ex) {
TRPC_FMT_ERROR("parse string to json ex:{} ", ex.what());
return false;
Expand Down
7 changes: 7 additions & 0 deletions trpc/config/trpc_conf_compatible_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -190,4 +190,11 @@ TEST_F(TrpcConfCompatibleTest, TransformConfig_JSON_Fail_WithIntegerOverflow) {
ASSERT_FALSE(trpc::config::GetInt64(json_value, "int_overflow", &v));
}

TEST_F(TrpcConfCompatibleTest, FindValueFromJson_json_string) {
std::string from = R"(1)";
Json::Value json_value;
bool trans_result = trpc::config::TransformConfig(from, &json_value);
ASSERT_FALSE(trans_result);
}

} // namespace trpc::testing
2 changes: 1 addition & 1 deletion trpc/runtime/iomodel/reactor/fiber/writing_buffer_list.cc
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ ssize_t WritingBufferList::FlushTo(IoHandler* io, ConnectionHandler* conn_handle
// We did write something out. Remove those buffers and update the result accordingly.
auto flushed = static_cast<std::size_t>(rc);
bool drained = false;
if (size_.fetch_sub(flushed, std::memory_order_acquire) < max_capacity) {
if (size_.fetch_sub(flushed, std::memory_order_acq_rel) - flushed < max_capacity) {
writable_cv_.notify_one();
}

Expand Down
4 changes: 2 additions & 2 deletions trpc/server/rpc/unary_rpc_method_handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ class UnaryRpcMethodHandler : public RpcMethodHandlerInterface {
private:
bool Serialize(serialization::Serialization* serialization, void* rsp, NoncontiguousBuffer& buff) {
serialization::DataType type;
if constexpr (std::is_convertible_v<RequestType*, google::protobuf::Message*>) {
if constexpr (std::is_convertible_v<RequestType*, google::protobuf::MessageLite*>) {
type = serialization::kPbMessage;
} else if constexpr (std::is_convertible_v<RequestType*, rapidjson::Document*>) {
type = serialization::kRapidJson;
Expand All @@ -219,7 +219,7 @@ class UnaryRpcMethodHandler : public RpcMethodHandlerInterface {

bool Deserialize(serialization::Serialization* serialization, NoncontiguousBuffer* req_data, void* req) {
serialization::DataType type;
if constexpr (std::is_convertible_v<RequestType*, google::protobuf::Message*>) {
if constexpr (std::is_convertible_v<RequestType*, google::protobuf::MessageLite*>) {
type = serialization::kPbMessage;
} else if constexpr (std::is_convertible_v<RequestType*, rapidjson::Document*>) {
type = serialization::kRapidJson;
Expand Down