]> git.ipfire.org Git - thirdparty/rspamd.git/commitdiff
[Minor] Fix various issues
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Tue, 15 Jan 2019 12:50:35 +0000 (12:50 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Tue, 15 Jan 2019 12:50:35 +0000 (12:50 +0000)
src/libmime/mime_expressions.c
src/lua/lua_html.c
src/plugins/regexp.c

index 6657570e7982bdbbc805369abe962809537558e9..bdc6e46f55eef81e453b57fe7e42e7228e14e947 100644 (file)
@@ -640,7 +640,7 @@ rspamd_mime_expr_parse (const gchar *line, gsize len,
 {
        rspamd_expression_atom_t *a = NULL;
        struct rspamd_mime_atom *mime_atom = NULL;
-       const gchar *p, *end;
+       const gchar *p, *end, *c = NULL;
        struct rspamd_mime_expr_ud *real_ud = (struct rspamd_mime_expr_ud *)ud;
        struct rspamd_config *cfg;
        rspamd_regexp_t *own_re;
@@ -656,6 +656,7 @@ rspamd_mime_expr_parse (const gchar *line, gsize len,
                in_flags_brace,
                got_obrace,
                in_function,
+               in_local_function,
                got_ebrace,
                end_atom,
                bad_atom
@@ -682,9 +683,8 @@ rspamd_mime_expr_parse (const gchar *line, gsize len,
                                if (t == ':') {
                                        if (p - line == 3 && memcmp (line, "lua", 3) == 0) {
                                                type = MIME_ATOM_LOCAL_LUA_FUNCTION;
-                                               state = end_atom;
-                                               p ++;
-                                               continue;
+                                               state = in_local_function;
+                                               c = p + 1;
                                        }
                                }
                                else {
@@ -759,6 +759,15 @@ rspamd_mime_expr_parse (const gchar *line, gsize len,
                        }
                        p ++;
                        break;
+               case in_local_function:
+                       if (!(g_ascii_isalnum (t) || t == '-' || t == '_')) {
+                               g_assert (c != NULL);
+                               state = end_atom;
+                       }
+                       else {
+                               p++;
+                       }
+                       break;
                case got_ebrace:
                        state = end_atom;
                        break;
@@ -783,15 +792,8 @@ set:
 
        mime_atom = rspamd_mempool_alloc (pool, sizeof (*mime_atom));
        mime_atom->type = type;
-
-       if (type != MIME_ATOM_LOCAL_LUA_FUNCTION) {
-               mime_atom->str = rspamd_mempool_alloc (pool, p - line + 1);
-               rspamd_strlcpy (mime_atom->str, line, p - line + 1);
-       }
-       else {
-               mime_atom->str = rspamd_mempool_alloc (pool, end - p + 1);
-               rspamd_strlcpy (mime_atom->str, p, end - p + 1);
-       }
+       mime_atom->str = rspamd_mempool_alloc (pool, p - line + 1);
+       rspamd_strlcpy (mime_atom->str, line, p - line + 1);
 
        if (type == MIME_ATOM_REGEXP) {
                mime_atom->d.re = rspamd_mime_expr_parse_regexp_atom (pool,
@@ -905,20 +907,20 @@ set:
 
                const ucl_object_t *function_obj;
 
-               function_obj = ucl_object_lookup_len (functions, p,
-                               end - p);
+               function_obj = ucl_object_lookup_len (functions, c,
+                               p - c);
 
                if (function_obj == NULL) {
                        g_set_error (err, rspamd_mime_expr_quark(), 320,
                                        "function %*.s is not found for '%s'",
-                                       (int)(end - p), p, mime_atom->str);
+                                       (int)(p - c), c, mime_atom->str);
                        goto err;
                }
 
                if (ucl_object_type (function_obj) != UCL_USERDATA) {
                        g_set_error (err, rspamd_mime_expr_quark(), 320,
                                        "function %*.s has invalid type for '%s'",
-                                       (int)(end - p), p, mime_atom->str);
+                                       (int)(p - c), c, mime_atom->str);
                        goto err;
                }
 
@@ -1111,15 +1113,24 @@ rspamd_mime_expr_process (struct rspamd_expr_process_data *process_data, rspamd_
                }
        }
        else if (mime_atom->type == MIME_ATOM_LOCAL_LUA_FUNCTION) {
+               gint err_idx;
+               GString *tb;
+
                L = task->cfg->lua_state;
+               lua_pushcfunction (L, &rspamd_lua_traceback);
+               err_idx = lua_gettop (L);
+
                lua_rawgeti (L, LUA_REGISTRYINDEX, mime_atom->d.lua_cbref);
                rspamd_lua_task_push (L, task);
 
-               if (lua_pcall (L, 1, 1, 0) != 0) {
-                       msg_info_task ("lua call to local function for atom '%s' failed: %s",
+               if (lua_pcall (L, 1, 1, err_idx) != 0) {
+                       tb = lua_touserdata (L, -1);
+                       msg_info_task ("lua call to local function for atom '%s' failed: %v",
                                        mime_atom->str,
-                                       lua_tostring (L, -1));
-                       lua_pop (L, 1);
+                                       tb);
+                       if (tb) {
+                               g_string_free (tb, TRUE);
+                       }
                }
                else {
                        if (lua_type (L, -1) == LUA_TBOOLEAN) {
@@ -1132,9 +1143,9 @@ rspamd_mime_expr_process (struct rspamd_expr_process_data *process_data, rspamd_
                                msg_err_task ("%s returned wrong return type: %s",
                                                mime_atom->str, lua_typename (L, lua_type (L, -1)));
                        }
-                       /* Remove result */
-                       lua_pop (L, 1);
                }
+
+               lua_settop (L, 0);
        }
        else {
                ret = rspamd_mime_expr_process_function (mime_atom->d.func, task,
index 71578e1a48506510f8ed6629e5f1a861b3d97935..739776b01eba1b1422c7f9c49b8a0b7692e51ba7 100644 (file)
@@ -315,6 +315,7 @@ lua_html_push_image (lua_State *L, struct html_image *img)
        lua_settable (L, -3);
        lua_pushstring (L, "embedded");
        lua_pushboolean (L, img->flags & RSPAMD_HTML_FLAG_IMAGE_EMBEDDED);
+       lua_settable (L, -3);
        lua_pushstring (L, "data");
        lua_pushboolean (L, img->flags & RSPAMD_HTML_FLAG_IMAGE_DATA);
        lua_settable (L, -3);
index 87ab1f9c00bdef8789135823a12e20136e5eb432..07d8e81b0221d59dfa5be9ddbec6a05b19b780cc 100644 (file)
@@ -223,7 +223,7 @@ regexp_module_config (struct rspamd_config *cfg)
                                        cur_item->symbol = ucl_object_key (value);
                                        cur_item->magic = rspamd_regexp_cb_magic;
                                        ud.cfg = cfg;
-                                       ud.conf_obj = elt;
+                                       ud.conf_obj = value;
 
                                        if (!read_regexp_expression (cfg->cfg_pool,
                                                        cur_item, ucl_object_key (value),