aboutsummaryrefslogtreecommitdiffstats
path: root/src/libserver/hyperscan_tools.cxx
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@rspamd.com>2022-11-13 20:43:20 +0000
committerVsevolod Stakhov <vsevolod@rspamd.com>2022-11-19 12:44:15 +0000
commita20335aaa10aa57f5f89e11c08f7a9575d004972 (patch)
tree7e0cd38b8a0f2d146db5a8bdcdf50b5d5f255d4b /src/libserver/hyperscan_tools.cxx
parent997a91110cc4eb63e7012d0b21b9a9bc5bdff325 (diff)
downloadrspamd-a20335aaa10aa57f5f89e11c08f7a9575d004972.tar.gz
rspamd-a20335aaa10aa57f5f89e11c08f7a9575d004972.zip
[Minor] Add some fail-safety for hyperscan cache
Diffstat (limited to 'src/libserver/hyperscan_tools.cxx')
-rw-r--r--src/libserver/hyperscan_tools.cxx14
1 files changed, 13 insertions, 1 deletions
diff --git a/src/libserver/hyperscan_tools.cxx b/src/libserver/hyperscan_tools.cxx
index 96366067d..2499b21ec 100644
--- a/src/libserver/hyperscan_tools.cxx
+++ b/src/libserver/hyperscan_tools.cxx
@@ -147,11 +147,23 @@ public:
}
void add_cached_file(const char *fname) {
-
auto mut_fname = std::string{fname};
std::size_t sz;
+
rspamd_normalize_path_inplace(mut_fname.data(), mut_fname.size(), &sz);
mut_fname.resize(sz);
+
+ if (mut_fname.empty()) {
+ msg_err_hyperscan("attempt to add an empty hyperscan file!");
+ return;
+ }
+
+ if (access(mut_fname.c_str(), R_OK) == -1) {
+ msg_err_hyperscan("attempt to add non existing hyperscan file: %s, %s", mut_fname.c_str(),
+ strerror(errno));
+ return;
+ }
+
auto dir = hs_known_files_cache::get_dir(mut_fname);
auto ext = hs_known_files_cache::get_extension(mut_fname);