From: Vsevolod Stakhov Date: Thu, 2 Mar 2023 09:46:05 +0000 (+0000) Subject: [Fix] Normalize glob paths to avoid hash table misses X-Git-Tag: 3.5~22 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=54451443604913b8239e2819147b0cb73817a860;p=thirdparty%2Frspamd.git [Fix] Normalize glob paths to avoid hash table misses --- diff --git a/src/libserver/hyperscan_tools.cxx b/src/libserver/hyperscan_tools.cxx index 296d273353..1953e9b32b 100644 --- a/src/libserver/hyperscan_tools.cxx +++ b/src/libserver/hyperscan_tools.cxx @@ -229,23 +229,27 @@ public: if (glob(glob_pattern.c_str(), 0, nullptr, &globbuf) == 0) { for (auto i = 0; i < globbuf.gl_pathc; i++) { - const auto *path = globbuf.gl_pathv[i]; + auto path = std::string{globbuf.gl_pathv[i]}; + std::size_t nsz; struct stat st; - if (stat(path, &st) == -1) { + rspamd_normalize_path_inplace(path.data(), path.size(), &nsz); + path.resize(nsz); + + if (stat(path.c_str(), &st) == -1) { msg_debug_hyperscan_lambda("cannot stat file %s: %s", - path, strerror(errno)); + path.c_str(), strerror(errno)); continue; } if (S_ISREG(st.st_mode)) { if (!known_cached_files.contains(path)) { - msg_info_hyperscan_lambda("remove stale hyperscan file %s", path); - unlink(path); + msg_info_hyperscan_lambda("remove stale hyperscan file %s", path.c_str()); + unlink(path.c_str()); } else { msg_debug_hyperscan_lambda("found known hyperscan file %s, size: %Hz", - path, st.st_size); + path.c_str(), st.st_size); } } }