aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/libserver/re_cache.c63
-rw-r--r--src/lua/lua_text.c18
-rw-r--r--src/lua/lua_util.c8
-rw-r--r--src/plugins/fuzzy_check.c174
-rw-r--r--src/rspamadm/lua_repl.c4
-rw-r--r--src/rspamadm/signtool.c1
6 files changed, 133 insertions, 135 deletions
diff --git a/src/libserver/re_cache.c b/src/libserver/re_cache.c
index 91ef2cfa4..3016d04c5 100644
--- a/src/libserver/re_cache.c
+++ b/src/libserver/re_cache.c
@@ -1892,7 +1892,7 @@ rspamd_re_cache_compile_timer_cb (EV_P_ ev_timer *w, int revents )
rspamd_cryptobox_fast_hash_state_t crc_st;
guint64 crc;
rspamd_regexp_t *re;
- hs_compile_error_t *hs_errors;
+ hs_compile_error_t *hs_errors = NULL;
guint *hs_flags = NULL;
const hs_expr_ext_t **hs_exts = NULL;
gchar **hs_pats = NULL;
@@ -2052,8 +2052,24 @@ rspamd_re_cache_compile_timer_cb (EV_P_ ev_timer *w, int revents )
/* Adjust real re number */
n = i;
+#define CLEANUP_ALLOCATED(is_err) do { \
+ g_free (hs_flags); \
+ g_free (hs_ids); \
+ for (guint j = 0; j < i; j ++) { \
+ g_free (hs_pats[j]); \
+ } \
+ g_free (hs_pats); \
+ g_free (hs_exts); \
+ if (is_err) { \
+ close (fd); \
+ unlink (path); \
+ if (hs_errors) hs_free_compile_error (hs_errors); \
+ } \
+} while(0)
+
if (n > 0) {
/* Create the hs tree */
+ hs_errors = NULL;
if (hs_compile_ext_multi ((const char **)hs_pats,
hs_flags,
hs_ids,
@@ -2064,35 +2080,15 @@ rspamd_re_cache_compile_timer_cb (EV_P_ ev_timer *w, int revents )
&test_db,
&hs_errors) != HS_SUCCESS) {
-
- g_free (hs_flags);
- g_free (hs_ids);
-
- for (guint j = 0; j < i; j ++) {
- g_free (hs_pats[j]);
- }
-
err = g_error_new (rspamd_re_cache_quark (), EINVAL,
"cannot create tree of regexp when processing '%s': %s",
hs_pats[hs_errors->expression], hs_errors->message);
- g_free (hs_pats);
- g_free (hs_exts);
- close (fd);
- unlink (path);
- hs_free_compile_error (hs_errors);
-
+ CLEANUP_ALLOCATED(true);
rspamd_re_cache_compile_err (EV_A_ w, err, cbdata, false);
return;
}
- for (guint j = 0; j < i; j ++) {
- g_free (hs_pats[j]);
- }
-
- g_free (hs_pats);
- g_free (hs_exts);
-
if (hs_serialize_database (test_db, &hs_serialized,
&serialized_len) != HS_SUCCESS) {
err = g_error_new (rspamd_re_cache_quark (),
@@ -2100,12 +2096,8 @@ rspamd_re_cache_compile_timer_cb (EV_P_ ev_timer *w, int revents )
"cannot serialize tree of regexp for %s",
re_class->hash);
- close (fd);
- unlink (path);
- g_free (hs_ids);
- g_free (hs_flags);
+ CLEANUP_ALLOCATED(true);
hs_free_database (test_db);
-
rspamd_re_cache_compile_err (EV_A_ w, err, cbdata, false);
return;
}
@@ -2157,10 +2149,8 @@ rspamd_re_cache_compile_timer_cb (EV_P_ ev_timer *w, int revents )
errno,
"cannot serialize tree of regexp to %s: %s",
path, strerror (errno));
- close (fd);
- unlink (path);
- g_free (hs_ids);
- g_free (hs_flags);
+
+ CLEANUP_ALLOCATED(true);
g_free (hs_serialized);
rspamd_re_cache_compile_err (EV_A_ w, err, cbdata, false);
@@ -2187,10 +2177,7 @@ rspamd_re_cache_compile_timer_cb (EV_P_ ev_timer *w, int revents )
}
cbdata->total += n;
-
- g_free (hs_serialized);
- g_free (hs_ids);
- g_free (hs_flags);
+ CLEANUP_ALLOCATED(false);
/* Now rename temporary file to the new .hs file */
rspamd_snprintf (npath, sizeof (npath), "%s%c%s.hs", cbdata->cache_dir,
@@ -2219,11 +2206,7 @@ rspamd_re_cache_compile_timer_cb (EV_P_ ev_timer *w, int revents )
(gint)g_hash_table_size (re_class->re),
path);
- g_free (hs_serialized);
- g_free (hs_ids);
- g_free (hs_flags);
- unlink (path);
- close (fd);
+ CLEANUP_ALLOCATED(true);
rspamd_re_cache_compile_err (EV_A_ w, err, cbdata, false);
return;
diff --git a/src/lua/lua_text.c b/src/lua/lua_text.c
index afda7d941..d1fd87ded 100644
--- a/src/lua/lua_text.c
+++ b/src/lua/lua_text.c
@@ -1398,7 +1398,7 @@ lua_text_find (lua_State *L)
}
#define BITOP(a,b,op) \
- ((a)[(gsize)(b)/(8*sizeof *(a))] op (gsize)1<<((gsize)(b)%(8*sizeof *(a))))
+ ((a)[(guint64)(b)/(8u*sizeof *(a))] op (guint64)1<<((guint64)(b)%(8u*sizeof *(a))))
static gint
lua_text_exclude_chars (lua_State *L)
@@ -1408,7 +1408,7 @@ lua_text_exclude_chars (lua_State *L)
gssize patlen;
const gchar *pat = lua_tolstring (L, 2, &patlen), *p, *end;
gchar *dest, *d;
- gsize byteset[32 / sizeof(gsize)]; /* Bitset for ascii */
+ guint64 byteset[32 / sizeof(guint64)]; /* Bitset for ascii */
gboolean copy = TRUE;
guint *plen;
@@ -1449,7 +1449,7 @@ lua_text_exclude_chars (lua_State *L)
if (patlen > 0) {
/*
- * This stuff assumes little endian, but GSIZE_FROM_LE should
+ * This stuff assumes little endian, but GUINT64_FROM_LE should
* deal with proper conversion
*/
switch (*pat) {
@@ -1458,22 +1458,22 @@ lua_text_exclude_chars (lua_State *L)
break;
case 's':
/* "\r\n\t\f " */
- byteset[0] |= GSIZE_FROM_LE (0x100003600);
+ byteset[0] |= GUINT64_FROM_LE(0x100003600LLU);
break;
case 'n':
/* newlines: "\r\n" */
- byteset[0] |= GSIZE_FROM_LE (0x2400);
+ byteset[0] |= GUINT64_FROM_LE (0x2400LLU);
break;
case '8':
/* 8 bit characters */
- byteset[2] |= GSIZE_FROM_LE (0xffffffffffffffffLLU);
- byteset[3] |= GSIZE_FROM_LE (0xffffffffffffffffLLU);
+ byteset[2] |= GUINT64_FROM_LE (0xffffffffffffffffLLU);
+ byteset[3] |= GUINT64_FROM_LE (0xffffffffffffffffLLU);
break;
case 'c':
/* Non printable (control) characters */
- byteset[0] |= GSIZE_FROM_LE (0xffffffff);
+ byteset[0] |= GUINT64_FROM_LE (0xffffffffLLU);
/* Del character */
- byteset[1] |= GSIZE_FROM_LE (0x8000000000000000);
+ byteset[1] |= GUINT64_FROM_LE (0x8000000000000000LLU);
break;
}
}
diff --git a/src/lua/lua_util.c b/src/lua/lua_util.c
index 1ac69365a..fd3db0774 100644
--- a/src/lua/lua_util.c
+++ b/src/lua/lua_util.c
@@ -1501,7 +1501,13 @@ lua_util_glob (lua_State *L)
pattern = luaL_checkstring (L, i);
if (pattern) {
- glob (pattern, flags, NULL, &gl);
+ if (glob (pattern, flags, NULL, &gl) != 0) {
+ /* There is no way to return error here, so just create an table */
+ lua_createtable (L, 0, 0);
+ globfree (&gl);
+
+ return 1;
+ }
}
}
diff --git a/src/plugins/fuzzy_check.c b/src/plugins/fuzzy_check.c
index e26ce2a77..3f5daea75 100644
--- a/src/plugins/fuzzy_check.c
+++ b/src/plugins/fuzzy_check.c
@@ -3768,6 +3768,11 @@ static gint
fuzzy_lua_learn_handler (lua_State *L)
{
struct rspamd_task *task = lua_check_task (L, 1);
+
+ if (task == NULL) {
+ return luaL_error(L, "invalid arguments");
+ }
+
guint flag = 0, weight = 1, send_flags = 0;
const gchar *symbol;
struct fuzzy_ctx *fuzzy_module_ctx = fuzzy_get_context (task->cfg);
@@ -3926,6 +3931,11 @@ static gint
fuzzy_lua_gen_hashes_handler (lua_State *L)
{
struct rspamd_task *task = lua_check_task (L, 1);
+
+ if (task == NULL) {
+ return luaL_error(L, "invalid arguments");
+ }
+
guint flag = 0, weight = 1, send_flags = 0;
const gchar *symbol;
struct fuzzy_ctx *fuzzy_module_ctx = fuzzy_get_context (task->cfg);
@@ -3934,120 +3944,116 @@ fuzzy_lua_gen_hashes_handler (lua_State *L)
gint cmd = FUZZY_WRITE;
gint i;
- if (task) {
- if (lua_type (L, 2) == LUA_TNUMBER) {
- flag = lua_tonumber (L, 2);
- }
- else if (lua_type (L, 2) == LUA_TSTRING) {
- struct fuzzy_rule *rule;
- guint i;
- GHashTableIter it;
- gpointer k, v;
- struct fuzzy_mapping *map;
+ if (lua_type (L, 2) == LUA_TNUMBER) {
+ flag = lua_tonumber (L, 2);
+ }
+ else if (lua_type (L, 2) == LUA_TSTRING) {
+ struct fuzzy_rule *rule;
+ guint i;
+ GHashTableIter it;
+ gpointer k, v;
+ struct fuzzy_mapping *map;
- symbol = lua_tostring (L, 2);
+ symbol = lua_tostring (L, 2);
- PTR_ARRAY_FOREACH (fuzzy_module_ctx->fuzzy_rules, i, rule) {
- if (flag != 0) {
- break;
- }
+ PTR_ARRAY_FOREACH (fuzzy_module_ctx->fuzzy_rules, i, rule) {
+ if (flag != 0) {
+ break;
+ }
- g_hash_table_iter_init (&it, rule->mappings);
+ g_hash_table_iter_init (&it, rule->mappings);
- while (g_hash_table_iter_next (&it, &k, &v)) {
- map = v;
+ while (g_hash_table_iter_next (&it, &k, &v)) {
+ map = v;
- if (g_ascii_strcasecmp (symbol, map->symbol) == 0) {
- flag = map->fuzzy_flag;
- break;
- }
+ if (g_ascii_strcasecmp (symbol, map->symbol) == 0) {
+ flag = map->fuzzy_flag;
+ break;
}
}
}
+ }
- if (flag == 0) {
- return luaL_error (L, "bad flag");
- }
+ if (flag == 0) {
+ return luaL_error (L, "bad flag");
+ }
- if (lua_type (L, 3) == LUA_TNUMBER) {
- weight = lua_tonumber (L, 3);
- }
+ if (lua_type (L, 3) == LUA_TNUMBER) {
+ weight = lua_tonumber (L, 3);
+ }
- /* Flags */
- if (lua_type (L, 4) == LUA_TTABLE) {
- const gchar *sf;
+ /* Flags */
+ if (lua_type (L, 4) == LUA_TTABLE) {
+ const gchar *sf;
- for (lua_pushnil (L); lua_next (L, -2); lua_pop (L, 1)) {
- sf = lua_tostring (L, -1);
+ for (lua_pushnil (L); lua_next (L, -2); lua_pop (L, 1)) {
+ sf = lua_tostring (L, -1);
- if (sf) {
- if (g_ascii_strcasecmp (sf, "noimages") == 0) {
- send_flags |= FUZZY_CHECK_FLAG_NOIMAGES;
- }
- else if (g_ascii_strcasecmp (sf, "noattachments") == 0) {
- send_flags |= FUZZY_CHECK_FLAG_NOATTACHMENTS;
- }
- else if (g_ascii_strcasecmp (sf, "notext") == 0) {
- send_flags |= FUZZY_CHECK_FLAG_NOTEXT;
- }
+ if (sf) {
+ if (g_ascii_strcasecmp (sf, "noimages") == 0) {
+ send_flags |= FUZZY_CHECK_FLAG_NOIMAGES;
+ }
+ else if (g_ascii_strcasecmp (sf, "noattachments") == 0) {
+ send_flags |= FUZZY_CHECK_FLAG_NOATTACHMENTS;
+ }
+ else if (g_ascii_strcasecmp (sf, "notext") == 0) {
+ send_flags |= FUZZY_CHECK_FLAG_NOTEXT;
}
}
}
+ }
- /* Type */
- if (lua_type (L, 5) == LUA_TSTRING) {
- const gchar *cmd_name = lua_tostring (L, 5);
+ /* Type */
+ if (lua_type (L, 5) == LUA_TSTRING) {
+ const gchar *cmd_name = lua_tostring (L, 5);
- if (strcmp (cmd_name, "add") == 0 || strcmp (cmd_name, "write") == 0) {
- cmd = FUZZY_WRITE;
- }
- else if (strcmp (cmd_name, "delete") == 0 || strcmp (cmd_name, "remove") == 0) {
- cmd = FUZZY_DEL;
- }
- else {
- return luaL_error (L, "invalid command: %s", cmd_name);
- }
+ if (strcmp (cmd_name, "add") == 0 || strcmp (cmd_name, "write") == 0) {
+ cmd = FUZZY_WRITE;
+ }
+ else if (strcmp (cmd_name, "delete") == 0 || strcmp (cmd_name, "remove") == 0) {
+ cmd = FUZZY_DEL;
+ }
+ else {
+ return luaL_error (L, "invalid command: %s", cmd_name);
}
+ }
- lua_createtable (L, 0, fuzzy_module_ctx->fuzzy_rules->len);
+ lua_createtable (L, 0, fuzzy_module_ctx->fuzzy_rules->len);
- PTR_ARRAY_FOREACH (fuzzy_module_ctx->fuzzy_rules, i, rule) {
- if (rule->read_only) {
- continue;
- }
+ PTR_ARRAY_FOREACH (fuzzy_module_ctx->fuzzy_rules, i, rule) {
+ if (rule->read_only) {
+ continue;
+ }
- /* Check for flag */
- if (g_hash_table_lookup (rule->mappings,
- GINT_TO_POINTER (flag)) == NULL) {
- msg_info_task ("skip rule %s as it has no flag %d defined"
- " false", rule->name, flag);
- continue;
- }
+ /* Check for flag */
+ if (g_hash_table_lookup (rule->mappings,
+ GINT_TO_POINTER (flag)) == NULL) {
+ msg_info_task ("skip rule %s as it has no flag %d defined"
+ " false", rule->name, flag);
+ continue;
+ }
- commands = fuzzy_generate_commands (task, rule, cmd, flag,
- weight, send_flags);
+ commands = fuzzy_generate_commands (task, rule, cmd, flag,
+ weight, send_flags);
- if (commands != NULL) {
- struct fuzzy_cmd_io *io;
- gint j;
+ if (commands != NULL) {
+ struct fuzzy_cmd_io *io;
+ gint j;
- lua_pushstring (L, rule->name);
- lua_createtable (L, commands->len, 0);
+ lua_pushstring (L, rule->name);
+ lua_createtable (L, commands->len, 0);
- PTR_ARRAY_FOREACH (commands, j, io) {
- lua_pushlstring (L, io->io.iov_base, io->io.iov_len);
- lua_rawseti (L, -2, j + 1);
- }
+ PTR_ARRAY_FOREACH (commands, j, io) {
+ lua_pushlstring (L, io->io.iov_base, io->io.iov_len);
+ lua_rawseti (L, -2, j + 1);
+ }
- lua_settable (L, -3); /* ret[rule->name] = {raw_fuzzy1, ..., raw_fuzzyn} */
+ lua_settable (L, -3); /* ret[rule->name] = {raw_fuzzy1, ..., raw_fuzzyn} */
- g_ptr_array_free (commands, TRUE);
- }
+ g_ptr_array_free (commands, TRUE);
}
}
- else {
- return luaL_error (L, "invalid arguments");
- }
+
return 1;
}
diff --git a/src/rspamadm/lua_repl.c b/src/rspamadm/lua_repl.c
index 70ce06cd2..c1925f0b4 100644
--- a/src/rspamadm/lua_repl.c
+++ b/src/rspamadm/lua_repl.c
@@ -385,7 +385,9 @@ rspamadm_lua_exec_handler (lua_State *L, gint argc, gchar **argv)
return;
}
- lua_repl_thread_call (thread, 0, argv[i], lua_thread_str_error_cb);
+ if (lua_repl_thread_call (thread, 0, argv[i], lua_thread_str_error_cb) != 0) {
+ return;
+ }
}
}
diff --git a/src/rspamadm/signtool.c b/src/rspamadm/signtool.c
index b236952e7..678ee42a6 100644
--- a/src/rspamadm/signtool.c
+++ b/src/rspamadm/signtool.c
@@ -374,6 +374,7 @@ rspamadm_sign_file (const gchar *fname, struct rspamd_cryptobox_keypair *kp)
if (b32_pk) {
rspamd_fprintf (pub_fp, "%v", b32_pk);
+ g_string_free (b32_pk, TRUE);
}
fclose (pub_fp);