From: Remi Gacogne Date: Fri, 10 Nov 2023 19:57:03 +0000 (+0100) Subject: Delint opendir/readdir related functions X-Git-Tag: rec-5.0.0-rc1~46^2~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=eacd6a7f346ab4c69df9b16f6d5904ac90d2c473;p=thirdparty%2Fpdns.git Delint opendir/readdir related functions --- diff --git a/pdns/dnsbackend.cc b/pdns/dnsbackend.cc index cfead8c159..7ef66280ac 100644 --- a/pdns/dnsbackend.cc +++ b/pdns/dnsbackend.cc @@ -119,8 +119,9 @@ void BackendMakerClass::load_all() return; } struct dirent* entry = nullptr; - //NOLINTNEXTLINE(concurrency-mt-unsafe): readdir is thread-safe nowadays and readdir_r is deprecated + // NOLINTNEXTLINE(concurrency-mt-unsafe): readdir is thread-safe nowadays and readdir_r is deprecated while ((entry = readdir(dir.get())) != nullptr) { + // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-array-to-pointer-decay): this is what dirent is auto name = std::string_view(entry->d_name, strlen(entry->d_name)); if (boost::starts_with(name, "lib") && name.size() > 13 && diff --git a/pdns/dnsdist-lua.cc b/pdns/dnsdist-lua.cc index 78490d7560..84f85344a3 100644 --- a/pdns/dnsdist-lua.cc +++ b/pdns/dnsdist-lua.cc @@ -1870,7 +1870,9 @@ static void setupLuaConfig(LuaContext& luaCtx, bool client, bool configCheck) } struct dirent* ent = nullptr; - while ((ent = readdir(dirp.get())) != NULL) { + // 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; } diff --git a/pdns/ixfrdist.cc b/pdns/ixfrdist.cc index 7192cd9958..d772cb217b 100644 --- a/pdns/ixfrdist.cc +++ b/pdns/ixfrdist.cc @@ -208,10 +208,13 @@ static void cleanUpDomain(const DNSName& domain, const uint16_t& keep, const str } 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; } + // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-array-to-pointer-decay): this is what dirent is zoneVersions.push_back(std::stoi(entry->d_name)); } dirHandle.reset(); diff --git a/pdns/ixfrutils.cc b/pdns/ixfrutils.cc index 12b0a3e11b..2fff8c580d 100644 --- a/pdns/ixfrutils.cc +++ b/pdns/ixfrutils.cc @@ -84,9 +84,10 @@ uint32_t getSerialFromDir(const std::string& dir) } struct dirent* entry = nullptr; - //NOLINTNEXTLINE(concurrency-mt-unsafe): readdir is thread-safe nowadays and readdir_r is deprecated + // NOLINTNEXTLINE(concurrency-mt-unsafe): readdir is thread-safe nowadays and readdir_r is deprecated while ((entry = readdir(dirhdl.get())) != nullptr) { uint32_t num = atoi(entry->d_name); + // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-array-to-pointer-decay): this is what dirent is auto name = std::string_view(entry->d_name, strlen(entry->d_name)); if (std::to_string(num) == name) { ret = max(num, ret); diff --git a/pdns/misc.cc b/pdns/misc.cc index 3cb1275d84..6e98949bed 100644 --- a/pdns/misc.cc +++ b/pdns/misc.cc @@ -1384,13 +1384,16 @@ uint64_t getOpenFileDescriptors(const std::string&) int ret = 0; struct dirent* entry = nullptr; - while ((entry = readdir(dirhdl.get()))) { + // NOLINTNEXTLINE(concurrency-mt-unsafe): readdir is thread-safe nowadays and readdir_r is deprecated + while ((entry = readdir(dirhdl.get())) != nullptr) { uint32_t num; try { + // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-array-to-pointer-decay): this is what dirent is pdns::checked_stoi_into(num, entry->d_name); } catch (...) { continue; // was not a number. } + // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-array-to-pointer-decay): this is what dirent is if (std::to_string(num) == entry->d_name) { ret++; }