]> git.ipfire.org Git - thirdparty/rspamd.git/commitdiff
[Fix] Reduce hyperscan_cache_file command from CONTROL_PATHLEN to 64 bytes
authorVsevolod Stakhov <vsevolod@rspamd.com>
Tue, 13 Jan 2026 10:44:42 +0000 (10:44 +0000)
committerVsevolod Stakhov <vsevolod@rspamd.com>
Tue, 13 Jan 2026 10:44:42 +0000 (10:44 +0000)
Send only the filename (hash.hs) instead of the full path in the
hyperscan cache notification. Main process reconstructs the full
path using cfg->hs_cache_dir.

This is the last CONTROL_PATHLEN field in rspamd_srv_command.

src/libserver/hyperscan_tools.cxx
src/libserver/rspamd_control.c
src/libserver/rspamd_control.h

index fcb83d1866cc61ac6546ee6091a382556efd8859..2922b8e611de6cd0b379b8734d810962fe40721d 100644 (file)
@@ -783,16 +783,25 @@ void rspamd_hyperscan_notice_known(const char *fname)
        rspamd::util::hs_known_files_cache::get().add_cached_file(fname);
 
        if (rspamd_current_worker != nullptr) {
-               /* Also notify main process */
+               /* Also notify main process - send only the basename */
                struct rspamd_srv_command notice_cmd;
+               const char *basename = strrchr(fname, '/');
 
-               if (strlen(fname) >= sizeof(notice_cmd.cmd.hyperscan_cache_file.path)) {
-                       msg_err("internal error: length of the filename %d ('%s') is larger than control buffer path: %d",
-                                       (int) strlen(fname), fname, (int) sizeof(notice_cmd.cmd.hyperscan_cache_file.path));
+               if (basename != nullptr) {
+                       basename++; /* Skip the '/' */
+               }
+               else {
+                       basename = fname; /* No '/' found, use the whole string */
+               }
+
+               if (strlen(basename) >= sizeof(notice_cmd.cmd.hyperscan_cache_file.filename)) {
+                       msg_err("internal error: length of the filename %d ('%s') is larger than control buffer: %d",
+                                       (int) strlen(basename), basename, (int) sizeof(notice_cmd.cmd.hyperscan_cache_file.filename));
                }
                else {
                        notice_cmd.type = RSPAMD_SRV_NOTICE_HYPERSCAN_CACHE;
-                       rspamd_strlcpy(notice_cmd.cmd.hyperscan_cache_file.path, fname, sizeof(notice_cmd.cmd.hyperscan_cache_file.path));
+                       rspamd_strlcpy(notice_cmd.cmd.hyperscan_cache_file.filename, basename,
+                                                  sizeof(notice_cmd.cmd.hyperscan_cache_file.filename));
                        rspamd_srv_send_command(rspamd_current_worker,
                                                                        rspamd_current_worker->srv->event_loop, &notice_cmd, -1,
                                                                        nullptr,
index 011f6220ed98f2f74d852f17ec47e7d38db8467a..9dcba2ce5885b1e8aba25ba59fe1780dec1b8824 100644 (file)
@@ -1238,7 +1238,14 @@ rspamd_srv_handler(EV_P_ ev_io *w, int revents)
                                break;
                        case RSPAMD_SRV_NOTICE_HYPERSCAN_CACHE:
 #ifdef WITH_HYPERSCAN
-                               rspamd_hyperscan_notice_known(cmd.cmd.hyperscan_cache_file.path);
+                               if (rspamd_main->cfg->hs_cache_dir != NULL &&
+                                       cmd.cmd.hyperscan_cache_file.filename[0] != '\0') {
+                                       char full_path[PATH_MAX];
+                                       rspamd_snprintf(full_path, sizeof(full_path), "%s/%s",
+                                                                       rspamd_main->cfg->hs_cache_dir,
+                                                                       cmd.cmd.hyperscan_cache_file.filename);
+                                       rspamd_hyperscan_notice_known(full_path);
+                               }
 #endif
                                rdata->rep.reply.hyperscan_cache_file.unused = 0;
                                break;
index 92cf5747d56e8202577feba27f6071c3e90c4127..e2bb7f6cab2b274eb160db54087689fff07dda45 100644 (file)
@@ -222,7 +222,7 @@ struct rspamd_srv_command {
                } health;
                /* Used when a worker loads a valid hyperscan file */
                struct {
-                       char path[CONTROL_PATHLEN];
+                       char filename[64]; /* Just the filename, not full path */
                } hyperscan_cache_file;
                /* Send when one worker has blocked some IP address */
                struct {