Fix potential nullptr names in resource_user/slice_allocator creation (#27154)

absl::string_view permits construction with nullptr, which yields UB.
This PR fixes all call sites that could have created these objects with
nullptr names.
pull/27160/head
AJ Heller 4 years ago committed by GitHub
parent 93275fc443
commit f84f3a7522
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      src/core/ext/transport/chttp2/transport/chttp2_slice_allocator.cc
  2. 2
      src/core/lib/iomgr/resource_quota.cc
  3. 3
      src/cpp/thread_manager/thread_manager.cc

@ -59,7 +59,7 @@ Chttp2SliceAllocatorFactory::~Chttp2SliceAllocatorFactory() {
std::unique_ptr<SliceAllocator>
Chttp2SliceAllocatorFactory::CreateSliceAllocator(absl::string_view peer_name) {
return absl::make_unique<Chttp2SliceAllocator>(
grpc_resource_user_create(resource_quota_, peer_name.data()));
grpc_resource_user_create(resource_quota_, peer_name));
}
} // namespace experimental

@ -804,7 +804,7 @@ grpc_resource_user* grpc_resource_user_create(
for (int i = 0; i < GRPC_RULIST_COUNT; i++) {
resource_user->links[i].next = resource_user->links[i].prev = nullptr;
}
if (name != nullptr) {
if (!name.empty()) {
resource_user->name = std::string(name);
} else {
resource_user->name = absl::StrCat(

@ -58,7 +58,8 @@ ThreadManager::ThreadManager(const char* name,
max_pollers_(max_pollers == -1 ? INT_MAX : max_pollers),
num_threads_(0),
max_active_threads_sofar_(0) {
resource_user_ = grpc_resource_user_create(resource_quota, name);
resource_user_ =
grpc_resource_user_create(resource_quota, name != nullptr ? name : "");
}
ThreadManager::~ThreadManager() {

Loading…
Cancel
Save