commit 2da8749: [Fix] Fix various issues with canonicalisation of the paths
Vsevolod Stakhov
vsevolod at rspamd.com
Fri Nov 10 15:35:03 UTC 2023
Author: Vsevolod Stakhov
Date: 2023-11-10 15:32:58 +0000
URL: https://github.com/rspamd/rspamd/commit/2da8749c237b51363c199fd2b6ce347d7f51cba6 (HEAD -> master)
[Fix] Fix various issues with canonicalisation of the paths
---
src/libserver/hyperscan_tools.cxx | 23 ++++++++++++++++-------
1 file changed, 16 insertions(+), 7 deletions(-)
diff --git a/src/libserver/hyperscan_tools.cxx b/src/libserver/hyperscan_tools.cxx
index 83f5360ae..7d1ecf337 100644
--- a/src/libserver/hyperscan_tools.cxx
+++ b/src/libserver/hyperscan_tools.cxx
@@ -122,8 +122,18 @@ public:
void add_cached_file(const raii_file &file)
{
- auto dir = file.get_dir();
- auto ext = file.get_extension();
+ auto fpath = std::filesystem::path{file.get_name()};
+ std::error_code ec;
+
+ fpath = std::filesystem::canonical(fpath, ec);
+
+ if (ec && ec.value() != 0) {
+ msg_err_hyperscan("invalid path: \"%s\", error message: %s", fpath.c_str(), ec.message().c_str());
+ return;
+ }
+
+ auto dir = fpath.parent_path();
+ auto ext = fpath.extension();
if (std::find_if(cache_dirs.begin(), cache_dirs.end(),
[&](const auto &item) { return item == dir; }) == std::end(cache_dirs)) {
@@ -134,11 +144,10 @@ public:
cache_extensions.emplace_back(std::string{ext});
}
- auto is_known = known_cached_files.insert(file.get_name());
- msg_debug_hyperscan("added %s hyperscan file: %*s",
+ auto is_known = known_cached_files.insert(fpath.string());
+ msg_debug_hyperscan("added %s hyperscan file: %s",
is_known.second ? "new" : "already known",
- (int) file.get_name().size(),
- file.get_name().data());
+ fpath.c_str());
}
void add_cached_file(const char *fname)
@@ -210,7 +219,7 @@ public:
for (const auto &ext: cache_extensions) {
glob_t globbuf;
- auto glob_pattern = fmt::format("{}{}*.{}",
+ auto glob_pattern = fmt::format("{}{}*{}",
dir, G_DIR_SEPARATOR_S, ext);
msg_debug_hyperscan_lambda("perform glob for pattern: %s",
glob_pattern.c_str());
More information about the Commits
mailing list