]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
global: Call getnam_r with a 64KiB buffer on the heap 60095/head
authorAdam Emerson <aemerson@redhat.com>
Wed, 2 Oct 2024 18:42:52 +0000 (14:42 -0400)
committerAdam Emerson <aemerson@redhat.com>
Thu, 3 Oct 2024 19:56:22 +0000 (15:56 -0400)
Fixes: https://tracker.ceph.com/issues/40692
Signed-off-by: Adam Emerson <aemerson@redhat.com>
src/global/global_init.cc

index 57ee5ee716717e32e267edc3353f3fc80f0905f4..79defaec3761c019790e2137206976a88e958a98 100644 (file)
@@ -13,6 +13,7 @@
  */
 
 #include <filesystem>
+#include <memory>
 #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<std::string,std::string> *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<char[]>(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;