aboutsummaryrefslogtreecommitdiffstats
path: root/src/libutil
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@rspamd.com>2023-02-27 10:56:27 +0000
committerVsevolod Stakhov <vsevolod@rspamd.com>2023-02-27 10:56:27 +0000
commite88a512b2f370b3fcf5b0ff1205a0a84d156e060 (patch)
treec2595353f6c501b669ac4b00b930c1d98470dc04 /src/libutil
parenta90fc658d7a2d360bc1b1311f7e5b7e08700c12d (diff)
downloadrspamd-e88a512b2f370b3fcf5b0ff1205a0a84d156e060.tar.gz
rspamd-e88a512b2f370b3fcf5b0ff1205a0a84d156e060.zip
[Fix] Add hyperscan databases sanity check
Issue: #4409
Diffstat (limited to 'src/libutil')
-rw-r--r--src/libutil/multipattern.c16
1 files changed, 10 insertions, 6 deletions
diff --git a/src/libutil/multipattern.c b/src/libutil/multipattern.c
index 0d6e8b4f4..e39374d42 100644
--- a/src/libutil/multipattern.c
+++ b/src/libutil/multipattern.c
@@ -429,8 +429,9 @@ rspamd_multipattern_try_save_hs (struct rspamd_multipattern *mp,
rspamd_snprintf (fp, sizeof (fp), "%s/%*xs.hsmp.tmp", hs_cache_dir,
(gint)rspamd_cryptobox_HASHBYTES / 2, hash);
- if ((fd = rspamd_file_xopen (fp, O_WRONLY | O_CREAT | O_EXCL, 00644, 0)) != -1) {
- if (hs_serialize_database (rspamd_hyperscan_get_database(mp->hs_db), &bytes, &len) == HS_SUCCESS) {
+ if ((fd = rspamd_file_xopen (fp, O_WRONLY | O_CREAT | O_EXCL, 00644, 1)) != -1) {
+ int ret;
+ if ((ret = hs_serialize_database (rspamd_hyperscan_get_database(mp->hs_db), &bytes, &len)) == HS_SUCCESS) {
if (write (fd, bytes, len) == -1) {
msg_warn ("cannot write hyperscan cache to %s: %s",
fp, strerror (errno));
@@ -455,14 +456,17 @@ rspamd_multipattern_try_save_hs (struct rspamd_multipattern *mp,
}
}
else {
- msg_warn ("cannot serialize hyperscan cache to %s: %s",
- fp, strerror (errno));
+ msg_warn ("cannot serialize hyperscan cache to %s: error code %d",
+ fp, ret);
unlink (fp);
}
close (fd);
}
+ else {
+ msg_warn ("cannot open a temp file %s to write hyperscan cache: %s", fp, strerror(errno));
+ }
}
#endif
@@ -515,9 +519,9 @@ rspamd_multipattern_compile (struct rspamd_multipattern *mp, GError **err)
/* Should not happen in the real life */
mp->hs_db = rspamd_hyperscan_from_raw_db(db, NULL);
}
- }
- rspamd_multipattern_try_save_hs (mp, hash);
+ rspamd_multipattern_try_save_hs (mp, hash);
+ }
for (i = 0; i < MAX_SCRATCH; i ++) {
mp->scratch[i] = NULL;