[binder] Fix crash when missing authority (#27321)

There is an assertion in Server::CallData::RecvInitialMetadataReady()
that checks whether the received initial metadata indeed contains keys
:authority and :path. However, there was no such check in the binder
transport. This PR calls recv_initial_metadata_ready with an error when
either :authority or :path is missing in the received initial metadata.
pull/27368/merge
Ta-Wei Tu 4 years ago committed by GitHub
parent 8c425189f3
commit 8c97369986
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 21
      src/core/ext/transport/binder/transport/binder_transport.cc

@ -172,6 +172,20 @@ static void cancel_stream_locked(grpc_binder_transport* gbt,
GRPC_ERROR_UNREF(error);
}
static bool ContainsAuthorityAndPath(const grpc_binder::Metadata& metadata) {
bool has_authority = false;
bool has_path = false;
for (const auto& kv : metadata) {
if (kv.first == grpc_core::StringViewFromSlice(GRPC_MDSTR_AUTHORITY)) {
has_authority = true;
}
if (kv.first == grpc_core::StringViewFromSlice(GRPC_MDSTR_PATH)) {
has_path = true;
}
}
return has_authority && has_path;
}
static void recv_initial_metadata_locked(void* arg,
grpc_error_handle /*error*/) {
RecvInitialMetadataArgs* args = static_cast<RecvInitialMetadataArgs*>(arg);
@ -189,6 +203,13 @@ static void recv_initial_metadata_locked(void* arg,
gpr_log(GPR_ERROR, "Failed to parse initial metadata");
return absl_status_to_grpc_error(args->initial_metadata.status());
}
if (!gbs->is_client) {
// For server, we expect :authority and :path in initial metadata.
if (!ContainsAuthorityAndPath(*args->initial_metadata)) {
return GRPC_ERROR_CREATE_FROM_CPP_STRING(
"Missing :authority or :path in initial metadata");
}
}
AssignMetadata(gbs->recv_initial_metadata, gbs->arena,
*args->initial_metadata);
return GRPC_ERROR_NONE;

Loading…
Cancel
Save