From a20335aaa10aa57f5f89e11c08f7a9575d004972 Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Sun, 13 Nov 2022 20:43:20 +0000 Subject: [PATCH] [Minor] Add some fail-safety for hyperscan cache --- src/libserver/hyperscan_tools.cxx | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) 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); -- 2.39.5