commit 5445144: [Fix] Normalize glob paths to avoid hash table misses

Vsevolod Stakhov vsevolod at rspamd.com
Thu Mar 2 09:49:03 UTC 2023


Author: Vsevolod Stakhov
Date: 2023-03-02 09:46:05 +0000
URL: https://github.com/rspamd/rspamd/commit/54451443604913b8239e2819147b0cb73817a860 (HEAD -> master)

[Fix] Normalize glob paths to avoid hash table misses

---
 src/libserver/hyperscan_tools.cxx | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)

diff --git a/src/libserver/hyperscan_tools.cxx b/src/libserver/hyperscan_tools.cxx
index 296d27335..1953e9b32 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);
 								}
 							}
 						}


More information about the Commits mailing list