Skip to content

Commit 9eeca73

Browse files
committed
global: Call getnam_r with a 64KiB buffer on the heap
Fixes: https://tracker.ceph.com/issues/40692 Signed-off-by: Adam Emerson <[email protected]>
1 parent bb2a220 commit 9eeca73

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/global/global_init.cc

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
*/
1414

1515
#include <filesystem>
16+
#include <memory>
1617
#include "common/async/context_pool.h"
1718
#include "common/ceph_argparse.h"
1819
#include "common/code_environment.h"
@@ -268,10 +269,14 @@ global_init(const std::map<std::string,std::string> *defaults,
268269
if (g_conf()->setgroup.length() > 0) {
269270
gid = atoi(g_conf()->setgroup.c_str());
270271
if (!gid) {
271-
char buf[4096];
272+
// There's no actual well-defined max that I could find in
273+
// library documentation. If we're allocating on the heap,
274+
// 64KiB seems at least reasonable.
275+
static constexpr std::size_t size = 64 * 1024;
276+
auto buf = std::make_unique_for_overwrite<char[]>(size);
272277
struct group gr;
273278
struct group *g = 0;
274-
getgrnam_r(g_conf()->setgroup.c_str(), &gr, buf, sizeof(buf), &g);
279+
getgrnam_r(g_conf()->setgroup.c_str(), &gr, buf.get(), size, &g);
275280
if (!g) {
276281
cerr << "unable to look up group '" << g_conf()->setgroup << "'"
277282
<< ": " << cpp_strerror(errno) << std::endl;

0 commit comments

Comments
 (0)