]> source.dussan.org Git - rspamd.git/commitdiff
[Minor] Do not write truncated hyperscan files
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Mon, 27 Jan 2020 13:51:39 +0000 (13:51 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Mon, 27 Jan 2020 13:51:39 +0000 (13:51 +0000)
src/libserver/protocol.c
src/libserver/re_cache.c

index 9ffdcd5c73166a492a2d5809ca7367354b60e534..71f1f363e0a4982c08db4ac99853d0ecd236dbc6 100644 (file)
@@ -1462,7 +1462,6 @@ rspamd_protocol_write_ucl (struct rspamd_task *task,
                dkim_sigs = rspamd_mempool_get_variable (task->task_pool,
                                RSPAMD_MEMPOOL_DKIM_SIGNATURE);
 
-
                if (dkim_sigs) {
                        if (dkim_sigs->next) {
                                /* Multiple DKIM signatures */
index 6889861ccc3828f5c4e171cc81d4bb684d5b60db..a2a6f9f1a0b90af12d105a566d2fcad56040577a 100644 (file)
@@ -2006,19 +2006,21 @@ rspamd_re_cache_compile_timer_cb (EV_P_ ev_timer *w, int revents )
 
                if (re_class->type_len > 0) {
                        msg_info_re_cache (
-                                       "compiled class %s(%*s) to cache %6s, %d regexps",
+                                       "compiled class %s(%*s) to cache %6s, %d/%d regexps",
                                        rspamd_re_cache_type_to_string (re_class->type),
                                        (gint) re_class->type_len - 1,
                                        re_class->type_data,
                                        re_class->hash,
-                                       n);
+                                       n,
+                                       (gint)g_hash_table_size (re_class->re));
                }
                else {
                        msg_info_re_cache (
-                                       "compiled class %s to cache %6s, %d regexps",
+                                       "compiled class %s to cache %6s, %d/%d regexps",
                                        rspamd_re_cache_type_to_string (re_class->type),
                                        re_class->hash,
-                                       n);
+                                       n,
+                                       (gint)g_hash_table_size (re_class->re));
                }
 
                cbdata->total += n;
@@ -2026,25 +2028,42 @@ rspamd_re_cache_compile_timer_cb (EV_P_ ev_timer *w, int revents )
                g_free (hs_serialized);
                g_free (hs_ids);
                g_free (hs_flags);
-       }
 
-       /* Now rename temporary file to the new .hs file */
-       rspamd_snprintf (npath, sizeof (path), "%s%c%s.hs", cbdata->cache_dir,
-                       G_DIR_SEPARATOR, re_class->hash);
+               /* Now rename temporary file to the new .hs file */
+               rspamd_snprintf (npath, sizeof (path), "%s%c%s.hs", cbdata->cache_dir,
+                               G_DIR_SEPARATOR, re_class->hash);
+
+               if (rename (path, npath) == -1) {
+                       err = g_error_new (rspamd_re_cache_quark (),
+                                       errno,
+                                       "cannot rename %s to %s: %s",
+                                       path, npath, strerror (errno));
+                       unlink (path);
+                       close (fd);
+
+                       rspamd_re_cache_compile_err (EV_A_ w, err, cbdata);
+                       return;
+               }
 
-       if (rename (path, npath) == -1) {
+               close (fd);
+       }
+       else {
                err = g_error_new (rspamd_re_cache_quark (),
                                errno,
-                               "cannot rename %s to %s: %s",
-                               path, npath, strerror (errno));
+                               "no suitable regular expressions %s (%d original): "
+                               "remove temporary file %s",
+                               rspamd_re_cache_type_to_string (re_class->type),
+                               (gint)g_hash_table_size (re_class->re),
+                               path);
                unlink (path);
                close (fd);
 
                rspamd_re_cache_compile_err (EV_A_ w, err, cbdata);
-               return;
+               unlink (path);
+               close (fd);
        }
 
-       close (fd);
+       /* Continue process */
        ev_timer_again (EV_A_ w);
 }