From b911de261ddc55e82e6569b7c837cc8acf609b02 Mon Sep 17 00:00:00 2001 From: Adam Emerson Date: Wed, 2 Oct 2024 14:42:52 -0400 Subject: [PATCH] global: Call getnam_r with a 64KiB buffer on the heap Fixes: https://tracker.ceph.com/issues/40692 Signed-off-by: Adam Emerson (cherry picked from commit 9eeca730fa0d99f39d81f6d16cb5faff9d033516) Fixes: https://tracker.ceph.com/issues/68389 Conflicts: src/global/global_init.cc - Replace `make_unique_for_overwrite` which is C++20 with `make_unique` Signed-off-by: Adam Emerson --- src/global/global_init.cc | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/global/global_init.cc b/src/global/global_init.cc index 57ee5ee716717..92aa56446a426 100644 --- a/src/global/global_init.cc +++ b/src/global/global_init.cc @@ -13,6 +13,7 @@ */ #include +#include #include "common/async/context_pool.h" #include "common/ceph_argparse.h" #include "common/code_environment.h" @@ -268,10 +269,14 @@ global_init(const std::map *defaults, if (g_conf()->setgroup.length() > 0) { gid = atoi(g_conf()->setgroup.c_str()); if (!gid) { - char buf[4096]; + // There's no actual well-defined max that I could find in + // library documentation. If we're allocating on the heap, + // 64KiB seems at least reasonable. + static constexpr std::size_t size = 64 * 1024; + auto buf = std::make_unique(size); struct group gr; struct group *g = 0; - getgrnam_r(g_conf()->setgroup.c_str(), &gr, buf, sizeof(buf), &g); + getgrnam_r(g_conf()->setgroup.c_str(), &gr, buf.get(), size, &g); if (!g) { cerr << "unable to look up group '" << g_conf()->setgroup << "'" << ": " << cpp_strerror(errno) << std::endl; -- 2.39.5