]> source.dussan.org Git - rspamd.git/commitdiff
[Minor] Add some fail-safety for hyperscan cache
authorVsevolod Stakhov <vsevolod@rspamd.com>
Sun, 13 Nov 2022 20:43:20 +0000 (20:43 +0000)
committerVsevolod Stakhov <vsevolod@rspamd.com>
Sat, 19 Nov 2022 12:44:15 +0000 (12:44 +0000)
src/libserver/hyperscan_tools.cxx

index 96366067de2d6cce2ea539e46d8ebb8ab3dea1ff..2499b21ec2da81dab14b6f3f245c389e709983d5 100644 (file)
@@ -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);