From: Vsevolod Stakhov Date: Tue, 13 Jan 2026 10:44:42 +0000 (+0000) Subject: [Fix] Reduce hyperscan_cache_file command from CONTROL_PATHLEN to 64 bytes X-Git-Tag: 4.0.0~201^2~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d1dbf5855e88f189a61bd21581d7ea5de9c15254;p=thirdparty%2Frspamd.git [Fix] Reduce hyperscan_cache_file command from CONTROL_PATHLEN to 64 bytes 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. --- diff --git a/src/libserver/hyperscan_tools.cxx b/src/libserver/hyperscan_tools.cxx index fcb83d1866..2922b8e611 100644 --- a/src/libserver/hyperscan_tools.cxx +++ b/src/libserver/hyperscan_tools.cxx @@ -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, ¬ice_cmd, -1, nullptr, diff --git a/src/libserver/rspamd_control.c b/src/libserver/rspamd_control.c index 011f6220ed..9dcba2ce58 100644 --- a/src/libserver/rspamd_control.c +++ b/src/libserver/rspamd_control.c @@ -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; diff --git a/src/libserver/rspamd_control.h b/src/libserver/rspamd_control.h index 92cf5747d5..e2bb7f6cab 100644 --- a/src/libserver/rspamd_control.h +++ b/src/libserver/rspamd_control.h @@ -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 {