]> source.dussan.org Git - rspamd.git/commitdiff
[Minor] Fix some more suspicious cases
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Sun, 7 Apr 2019 08:44:58 +0000 (09:44 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Sun, 7 Apr 2019 08:45:16 +0000 (09:45 +0100)
src/libserver/url.c
src/libstat/tokenizers/tokenizers.c
src/libutil/hash.c
src/libutil/str_util.c
src/lua/lua_util.c

index d774eb44010326e0922bedd4cef27cbf2451cdb2..8ad073ae210a12e150124f4046b40e04ef976f2a 100644 (file)
@@ -3126,7 +3126,7 @@ rspamd_url_hash (gconstpointer u)
        const struct rspamd_url *url = u;
 
        if (url->urllen > 0) {
-               return rspamd_cryptobox_fast_hash (url->string, url->urllen,
+               return (guint)rspamd_cryptobox_fast_hash (url->string, url->urllen,
                                rspamd_hash_seed ());
        }
 
@@ -3139,7 +3139,7 @@ rspamd_url_host_hash (gconstpointer u)
        const struct rspamd_url *url = u;
 
        if (url->hostlen > 0) {
-               return rspamd_cryptobox_fast_hash (url->host, url->hostlen,
+               return (guint)rspamd_cryptobox_fast_hash (url->host, url->hostlen,
                                rspamd_hash_seed ());
        }
 
@@ -3162,7 +3162,7 @@ rspamd_email_hash (gconstpointer u)
                rspamd_cryptobox_fast_hash_update (&st, url->user, url->userlen);
        }
 
-       return rspamd_cryptobox_fast_hash_final (&st);
+       return (guint)rspamd_cryptobox_fast_hash_final (&st);
 }
 
 /* Compare two emails for building emails tree */
index caa4a48a5d1ea603f4f34a3ceb7bce6f1a1871c0..b6061ce3b41150f34cb02fbfeeafad2b85e470d5 100644 (file)
@@ -217,10 +217,10 @@ rspamd_tokenize_check_limit (gboolean decay,
 }
 
 static inline gboolean
-rspamd_utf_word_valid (const gchar *text, const gchar *end,
+rspamd_utf_word_valid (const guchar *text, const guchar *end,
                gint32 start, gint32 finish)
 {
-       const gchar *st = text + start, *fin = text + finish;
+       const guchar *st = text + start, *fin = text + finish;
        UChar32 c;
 
        if (st >= end || fin > end || st >= fin) {
index c40200f64fe4a04280f087968388699f1139260d..56e80a17e2f764280ab445c065c8a3713f7008cb 100644 (file)
@@ -628,7 +628,7 @@ rspamd_lru_hash_insert (rspamd_lru_hash_t *hash,
        node->data = value;
        node->lg_usages = (guint8)lfu_base_value;
        node->last = TIME_TO_TS (now);
-       node->eviction_pos = -1;
+       node->eviction_pos = (guint8)-1;
 
        if (ret != 0) {
                /* Also need to check maxsize */
index d32a0d4d1b085c5f552a3755ea6dcc8a524844eb..290110b2bd9539e8751e4304deae62eb78c1d778 100644 (file)
@@ -334,7 +334,7 @@ rspamd_gstring_icase_hash (gconstpointer key)
 {
        const GString *f = key;
 
-       return rspamd_icase_hash (f->str, f->len, rspamd_hash_seed ());
+       return (guint)rspamd_icase_hash (f->str, f->len, rspamd_hash_seed ());
 }
 
 /* https://graphics.stanford.edu/~seander/bithacks.html#ZeroInWord */
index 25fdc15144d4c5fb6899367d428c8669daaeefb9..ec5f98c22909a6bac9c2413b2887aae41cc29017 100644 (file)
@@ -2513,30 +2513,41 @@ lua_util_is_utf_mixed_script(lua_State *L)
 {
        LUA_TRACE_POINT;
        gsize len_of_string;
-       const gchar *string_to_check = lua_tolstring (L, 1, &len_of_string);
+       const guchar *string_to_check = lua_tolstring (L, 1, &len_of_string);
        UScriptCode last_script_code = USCRIPT_INVALID_CODE;
        UErrorCode uc_err = U_ZERO_ERROR;
 
        if (string_to_check) {
                uint index = 0;
                UChar32 char_to_check = 0;
-               while(index < len_of_string) {
-                       U8_NEXT(string_to_check, index, len_of_string, char_to_check);
-                       if (char_to_check < 0 ) {
+
+               while (index < len_of_string) {
+                       U8_NEXT (string_to_check, index, len_of_string, char_to_check);
+
+                       if (char_to_check < 0) {
                                return luaL_error (L, "passed string is not valid utf");
                        }
-                       UScriptCode current_script_code = uscript_getScript(char_to_check, &uc_err);
-                       if (uc_err != U_ZERO_ERROR){
-                               msg_err ("cannot get unicode script for character, error: %s", u_errorName (uc_err));
+
+                       UScriptCode current_script_code = uscript_getScript (char_to_check, &uc_err);
+
+                       if (uc_err != U_ZERO_ERROR) {
+                               msg_err ("cannot get unicode script for character, error: %s",
+                                               u_errorName (uc_err));
                                lua_pushboolean (L, false);
+
                                return 1;
                        }
-                       if ( current_script_code != USCRIPT_COMMON && current_script_code != USCRIPT_INHERITED ){
-                               if (last_script_code == USCRIPT_INVALID_CODE ){
+
+                       if (current_script_code != USCRIPT_COMMON &&
+                               current_script_code != USCRIPT_INHERITED) {
+
+                               if (last_script_code == USCRIPT_INVALID_CODE) {
                                        last_script_code = current_script_code;
-                               } else {
-                                       if ( last_script_code != current_script_code ){
+                               }
+                               else {
+                                       if (last_script_code != current_script_code) {
                                                lua_pushboolean (L, true);
+
                                                return 1;
                                        }
                                }