From: Adam Emerson Date: Wed, 2 Oct 2024 18:42:52 +0000 (-0400) Subject: global: Call getnam_r with a 64KiB buffer on the heap X-Git-Tag: v20.0.0~913^2 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=refs%2Fpull%2F60095%2Fhead;p=ceph.git global: Call getnam_r with a 64KiB buffer on the heap Fixes: https://tracker.ceph.com/issues/40692 Signed-off-by: Adam Emerson --- diff --git a/src/global/global_init.cc b/src/global/global_init.cc index 57ee5ee716717..79defaec3761c 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_for_overwrite(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;