From: Vsevolod Stakhov Date: Mon, 27 Jan 2020 13:51:39 +0000 (+0000) Subject: [Minor] Do not write truncated hyperscan files X-Git-Tag: 2.3~42 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=92880f3694246c041d768811a98a4db3fdf7f00a;p=rspamd.git [Minor] Do not write truncated hyperscan files --- diff --git a/src/libserver/protocol.c b/src/libserver/protocol.c index 9ffdcd5c7..71f1f363e 100644 --- a/src/libserver/protocol.c +++ b/src/libserver/protocol.c @@ -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 */ diff --git a/src/libserver/re_cache.c b/src/libserver/re_cache.c index 6889861cc..a2a6f9f1a 100644 --- a/src/libserver/re_cache.c +++ b/src/libserver/re_cache.c @@ -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); }