MCPcopy Create free account
hub / github.com/apache/brpc / ParseRpcMessage

Function ParseRpcMessage

src/brpc/policy/baidu_rpc_protocol.cpp:105–146  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

103}
104
105ParseResult ParseRpcMessage(butil::IOBuf* source, Socket* socket,
106 bool /*read_eof*/, const void*) {
107 char header_buf[12];
108 const size_t n = source->copy_to(header_buf, sizeof(header_buf));
109 if (n >= 4) {
110 void* dummy = header_buf;
111 if (*(const uint32_t*)dummy != *(const uint32_t*)"PRPC") {
112 return MakeParseError(PARSE_ERROR_TRY_OTHERS);
113 }
114 } else {
115 if (memcmp(header_buf, "PRPC", n) != 0) {
116 return MakeParseError(PARSE_ERROR_TRY_OTHERS);
117 }
118 }
119 if (n < sizeof(header_buf)) {
120 return MakeParseError(PARSE_ERROR_NOT_ENOUGH_DATA);
121 }
122 uint32_t body_size;
123 uint32_t meta_size;
124 butil::RawUnpacker(header_buf + 4).unpack32(body_size).unpack32(meta_size);
125 if (body_size > FLAGS_max_body_size) {
126 // We need this log to report the body_size to give users some clues
127 // which is not printed in InputMessenger.
128 LOG(ERROR) << "body_size=" << body_size << " from "
129 << socket->remote_side() << " is too large";
130 return MakeParseError(PARSE_ERROR_TOO_BIG_DATA);
131 } else if (source->length() < sizeof(header_buf) + body_size) {
132 return MakeParseError(PARSE_ERROR_NOT_ENOUGH_DATA);
133 }
134 if (meta_size > body_size) {
135 LOG(ERROR) << "meta_size=" << meta_size << " is bigger than body_size="
136 << body_size;
137 // Pop the message
138 source->pop_front(sizeof(header_buf) + body_size);
139 return MakeParseError(PARSE_ERROR_TRY_OTHERS);
140 }
141 source->pop_front(sizeof(header_buf));
142 MostCommonMessage* msg = MostCommonMessage::Get();
143 source->cutn(&msg->meta, meta_size);
144 source->cutn(&msg->payload, body_size - meta_size);
145 return MakeMessage(msg);
146}
147
148bool SerializeRpcMessage(const google::protobuf::Message& message,
149 Controller& cntl, ContentType content_type,

Callers 2

LLVMFuzzerTestOneInputFunction · 0.85
HandleRpcResponseMethod · 0.85

Calls 9

MakeParseErrorFunction · 0.85
RawUnpackerClass · 0.85
GetFunction · 0.85
MakeMessageFunction · 0.85
copy_toMethod · 0.45
remote_sideMethod · 0.45
lengthMethod · 0.45
pop_frontMethod · 0.45
cutnMethod · 0.45

Tested by

no test coverage detected