From: Remi Gacogne Date: Mon, 13 Nov 2023 11:30:17 +0000 (+0100) Subject: Apply suggestions from Fred's review (thanks!) X-Git-Tag: rec-5.0.0-rc1~46^2~1 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=694c668c21c20a606d9843bfa65e902a1e310d4d;p=thirdparty%2Fpdns.git Apply suggestions from Fred's review (thanks!) --- diff --git a/modules/geoipbackend/geoipbackend.cc b/modules/geoipbackend/geoipbackend.cc index 681bf6d926..1f8e997663 100644 --- a/modules/geoipbackend/geoipbackend.cc +++ b/modules/geoipbackend/geoipbackend.cc @@ -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(); diff --git a/pdns/dnsdist-lua.cc b/pdns/dnsdist-lua.cc index 84f85344a3..2f2dce8451 100644 --- a/pdns/dnsdist-lua.cc +++ b/pdns/dnsdist-lua.cc @@ -1861,35 +1861,36 @@ static void setupLuaConfig(LuaContext& luaCtx, bool client, bool configCheck) return; } - auto dirp = std::unique_ptr(opendir(dirname.c_str()), closedir); std::vector 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(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; diff --git a/pdns/dnsdistdist/.gitignore b/pdns/dnsdistdist/.gitignore index 8e22528413..5033a20ffc 100644 --- a/pdns/dnsdistdist/.gitignore +++ b/pdns/dnsdistdist/.gitignore @@ -34,6 +34,7 @@ /missing /testrunner /dnsdist +/fuzz_target_dnsdistcache /*.pb.cc /*.pb.h /dnsdist.service diff --git a/pdns/ixfrdist.cc b/pdns/ixfrdist.cc index d772cb217b..b9daff9d9f 100644 --- a/pdns/ixfrdist.cc +++ b/pdns/ixfrdist.cc @@ -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(opendir(dir.c_str()), closedir); - if (!dirHandle) { - return; - } vector 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(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<(opendir(("/proc/"+std::to_string(getpid())+"/fd/").c_str()), closedir); - if (!dirhdl) { + auto dirHandle = std::unique_ptr(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