]> git.ipfire.org Git - thirdparty/rspamd.git/commitdiff
[Minor] Fix some issues
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Sat, 16 Oct 2021 12:01:44 +0000 (13:01 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Sat, 16 Oct 2021 12:01:44 +0000 (13:01 +0100)
Found by: coverity scan

src/lua/lua_text.c
src/plugins/fuzzy_check.c
src/rspamadm/signtool.c

index afda7d9413f33fc114dcfe5113d98efb0f03988e..d1fd87ded9a602799292d84e14d91ab0cc6b6746 100644 (file)
@@ -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;
                                        }
                                }
index e26ce2a774b5cbbf425dbfb70cd59c79cee007f1..3f5daea75279a64f2a74d3dd81a1e8ecb6e411cf 100644 (file)
@@ -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;
 }
index b236952e7e22052e9ca75d8ff1278d171f7c8231..678ee42a603eedcec09ce504ac87942958af0831 100644 (file)
@@ -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);