diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2016-07-29 13:54:58 +0100 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2016-07-29 13:54:58 +0100 |
commit | 62b8b657d9d07844b8b72d21df5b8e66ee84ac43 (patch) | |
tree | 9a5ccdd08119128a16bbc35e7d635fa495f26827 /src/libserver | |
parent | 6ccd44320e725ed542883491af7d6b17a2f4a6eb (diff) | |
download | rspamd-62b8b657d9d07844b8b72d21df5b8e66ee84ac43.tar.gz rspamd-62b8b657d9d07844b8b72d21df5b8e66ee84ac43.zip |
[Fix] Ensure that hyperscan cache written is written properly
Diffstat (limited to 'src/libserver')
-rw-r--r-- | src/libserver/re_cache.c | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/src/libserver/re_cache.c b/src/libserver/re_cache.c index dc993513c..9fa2688a2 100644 --- a/src/libserver/re_cache.c +++ b/src/libserver/re_cache.c @@ -1318,7 +1318,7 @@ rspamd_re_cache_compile_hyperscan (struct rspamd_re_cache *cache, GHashTableIter it, cit; gpointer k, v; struct rspamd_re_class *re_class; - gchar path[PATH_MAX]; + gchar path[PATH_MAX], npath[PATH_MAX]; hs_database_t *test_db; gint fd, i, n, *hs_ids = NULL, pcre_flags, re_flags; guint64 crc; @@ -1371,6 +1371,8 @@ rspamd_re_cache_compile_hyperscan (struct rspamd_re_cache *cache, continue; } + rspamd_snprintf (path, sizeof (path), "%s%c%s.hs.new", cache_dir, + G_DIR_SEPARATOR, re_class->hash); fd = open (path, O_CREAT|O_TRUNC|O_EXCL|O_WRONLY, 00600); if (fd == -1) { @@ -1471,6 +1473,7 @@ rspamd_re_cache_compile_hyperscan (struct rspamd_re_cache *cache, g_free (hs_ids); g_free (hs_pats); close (fd); + unlink (path); hs_free_compile_error (hs_errors); return -1; @@ -1487,6 +1490,7 @@ rspamd_re_cache_compile_hyperscan (struct rspamd_re_cache *cache, re_class->hash); close (fd); + unlink (path); g_free (hs_ids); g_free (hs_flags); hs_free_database (test_db); @@ -1514,6 +1518,7 @@ rspamd_re_cache_compile_hyperscan (struct rspamd_re_cache *cache, else { iov[0].iov_base = (void *) rspamd_hs_magic; } + iov[0].iov_len = RSPAMD_HS_MAGIC_LEN; iov[1].iov_base = &cache->plt; iov[1].iov_len = sizeof (cache->plt); @@ -1535,6 +1540,7 @@ rspamd_re_cache_compile_hyperscan (struct rspamd_re_cache *cache, "cannot serialize tree of regexp to %s: %s", path, strerror (errno)); close (fd); + unlink (path); g_free (hs_ids); g_free (hs_flags); g_free (hs_serialized); @@ -1566,7 +1572,10 @@ rspamd_re_cache_compile_hyperscan (struct rspamd_re_cache *cache, g_free (hs_flags); } + fsync (fd); close (fd); + + /* Now rename temporary file to the new .hs file */ } return total; |