Skip to content

Commit

Permalink
[Minor] Do not write truncated hyperscan files
Browse files Browse the repository at this point in the history
  • Loading branch information
vstakhov committed Jan 27, 2020
1 parent dadb994 commit 92880f3
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 14 deletions.
1 change: 0 additions & 1 deletion src/libserver/protocol.c
Expand Up @@ -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 */
Expand Down
45 changes: 32 additions & 13 deletions src/libserver/re_cache.c
Expand Up @@ -2006,45 +2006,64 @@ 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;

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);
}

Expand Down

0 comments on commit 92880f3

Please sign in to comment.