]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Apply suggestions from Fred's review (thanks!)
authorRemi Gacogne <remi.gacogne@powerdns.com>
Mon, 13 Nov 2023 11:30:17 +0000 (12:30 +0100)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Mon, 13 Nov 2023 11:30:17 +0000 (12:30 +0100)
modules/geoipbackend/geoipbackend.cc
pdns/dnsdist-lua.cc
pdns/dnsdistdist/.gitignore
pdns/ixfrdist.cc
pdns/misc.cc

index 681bf6d926407e6ec038d4d37f24a7f229fb18b4..1f8e997663b4ca231aa3b1871449864473120d2d 100644 (file)
@@ -90,7 +90,6 @@ GeoIPBackend::GeoIPBackend(const string& suffix)
       throw PDNSException("dnssec-keydir " + getArg("dnssec-keydir") + " does not exist");
     }
     d_dnssec = true;
-    dirHandle.reset();
   }
   if (s_rc == 0) { // first instance gets to open everything
     initialize();
index 84f85344a33cc026f328fd103be8211594b833c2..2f2dce84510d13574ee5a9b1e5e082c9763cf2a1 100644 (file)
@@ -1861,35 +1861,36 @@ static void setupLuaConfig(LuaContext& luaCtx, bool client, bool configCheck)
       return;
     }
 
-    auto dirp = std::unique_ptr<DIR, decltype(&closedir)>(opendir(dirname.c_str()), closedir);
     std::vector<std::string> files;
-    if (!dirp) {
-      errlog("Error opening the included directory %s!", dirname.c_str());
-      g_outputBuffer = "Error opening the included directory " + dirname + "!";
-      return;
-    }
-
-    struct dirent* ent = nullptr;
-    // NOLINTNEXTLINE(concurrency-mt-unsafe): readdir is thread-safe nowadays and readdir_r is deprecated
-    while ((ent = readdir(dirp.get())) != nullptr) {
-      // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-array-to-pointer-decay): this is what dirent is
-      if (ent->d_name[0] == '.') {
-        continue;
+    {
+      auto dirHandle = std::unique_ptr<DIR, decltype(&closedir)>(opendir(dirname.c_str()), closedir);
+      if (!dirHandle) {
+        errlog("Error opening the included directory %s!", dirname.c_str());
+        g_outputBuffer = "Error opening the included directory " + dirname + "!";
+        return;
       }
 
-      if (boost::ends_with(ent->d_name, ".conf")) {
-        std::ostringstream namebuf;
-        namebuf << dirname << "/" << ent->d_name;
-
-        if (stat(namebuf.str().c_str(), &st) || !S_ISREG(st.st_mode)) {
+      struct dirent* ent = nullptr;
+      // NOLINTNEXTLINE(concurrency-mt-unsafe): readdir is thread-safe nowadays and readdir_r is deprecated
+      while ((ent = readdir(dirHandle.get())) != nullptr) {
+        // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-array-to-pointer-decay): this is what dirent is
+        if (ent->d_name[0] == '.') {
           continue;
         }
 
-        files.push_back(namebuf.str());
+        if (boost::ends_with(ent->d_name, ".conf")) {
+          std::ostringstream namebuf;
+          namebuf << dirname << "/" << ent->d_name;
+
+          if (stat(namebuf.str().c_str(), &st) || !S_ISREG(st.st_mode)) {
+            continue;
+          }
+
+          files.push_back(namebuf.str());
+        }
       }
     }
 
-    dirp.reset();
     std::sort(files.begin(), files.end());
 
     g_included = true;
index 8e22528413dd4a92affeabdb317e5b47ae481979..5033a20ffc4c385acc139fcdbabea5f3642ced4f 100644 (file)
@@ -34,6 +34,7 @@
 /missing
 /testrunner
 /dnsdist
+/fuzz_target_dnsdistcache
 /*.pb.cc
 /*.pb.h
 /dnsdist.service
index d772cb217b2c30037bb103be26a24d302d39bedd..b9daff9d9f94e40fdd253f9391e2f25a9f9d69d9 100644 (file)
@@ -202,22 +202,25 @@ static bool sortSOA(uint32_t i, uint32_t j) {
 
 static void cleanUpDomain(const DNSName& domain, const uint16_t& keep, const string& workdir) {
   string dir = workdir + "/" + domain.toString();
-  auto dirHandle = std::unique_ptr<DIR, decltype(&closedir)>(opendir(dir.c_str()), closedir);
-  if (!dirHandle) {
-    return;
-  }
   vector<uint32_t> zoneVersions;
-  struct dirent* entry = nullptr;
-  // NOLINTNEXTLINE(concurrency-mt-unsafe): readdir is thread-safe nowadays and readdir_r is deprecated
-  while ((entry = readdir(dirHandle.get())) != nullptr) {
-    // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-array-to-pointer-decay): this is what dirent is
-    if (strcmp(entry->d_name, ".") == 0 || strcmp(entry->d_name, "..") == 0) {
-      continue;
+  {
+    auto dirHandle = std::unique_ptr<DIR, decltype(&closedir)>(opendir(dir.c_str()), closedir);
+    if (!dirHandle) {
+      return;
+    }
+
+    struct dirent* entry = nullptr;
+    // NOLINTNEXTLINE(concurrency-mt-unsafe): readdir is thread-safe nowadays and readdir_r is deprecated
+    while ((entry = readdir(dirHandle.get())) != nullptr) {
+      // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-array-to-pointer-decay): this is what dirent is
+      if (strcmp(entry->d_name, ".") == 0 || strcmp(entry->d_name, "..") == 0) {
+        continue;
+      }
+      //  NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-array-to-pointer-decay): this is what dirent is
+      zoneVersions.push_back(std::stoi(entry->d_name));
     }
-    //  NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-array-to-pointer-decay): this is what dirent is
-    zoneVersions.push_back(std::stoi(entry->d_name));
   }
-  dirHandle.reset();
+
   g_log<<Logger::Info<<"Found "<<zoneVersions.size()<<" versions of "<<domain<<", asked to keep "<<keep<<", ";
   if (zoneVersions.size() <= keep) {
     g_log<<Logger::Info<<"not cleaning up"<<endl;
index 6e98949bedda7489dc2cb8846e4a53f03e9ba3fa..bb5464f286be964696a41fbc0cb09ca103af514c 100644 (file)
@@ -1377,15 +1377,15 @@ DNSName getTSIGAlgoName(TSIGHashEnum& algoEnum)
 uint64_t getOpenFileDescriptors(const std::string&)
 {
 #ifdef __linux__
-  auto dirhdl = std::unique_ptr<DIR, decltype(&closedir)>(opendir(("/proc/"+std::to_string(getpid())+"/fd/").c_str()), closedir);
-  if (!dirhdl) {
+  auto dirHandle = std::unique_ptr<DIR, decltype(&closedir)>(opendir(("/proc/"+std::to_string(getpid())+"/fd/").c_str()), closedir);
+  if (!dirHandle) {
     return 0;
   }
 
   int ret = 0;
   struct dirent* entry = nullptr;
   // NOLINTNEXTLINE(concurrency-mt-unsafe): readdir is thread-safe nowadays and readdir_r is deprecated
-  while ((entry = readdir(dirhdl.get())) != nullptr) {
+  while ((entry = readdir(dirHandle.get())) != nullptr) {
     uint32_t num;
     try {
       // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-array-to-pointer-decay): this is what dirent is