commit a20335a: [Minor] Add some fail-safety for hyperscan cache

Vsevolod Stakhov vsevolod at rspamd.com
Sat Nov 19 20:28:19 UTC 2022


Author: Vsevolod Stakhov
Date: 2022-11-13 20:43:20 +0000
URL: https://github.com/rspamd/rspamd/commit/a20335aaa10aa57f5f89e11c08f7a9575d004972

[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);
 


More information about the Commits mailing list