From 545e090c81ce22bbb7edb6d3621c348bd994449c Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Sun, 7 Apr 2019 09:44:58 +0100 Subject: [PATCH] [Minor] Fix some more suspicious cases --- src/libserver/url.c | 6 +++--- src/libstat/tokenizers/tokenizers.c | 4 ++-- src/libutil/hash.c | 2 +- src/libutil/str_util.c | 2 +- src/lua/lua_util.c | 33 +++++++++++++++++++---------- 5 files changed, 29 insertions(+), 18 deletions(-) diff --git a/src/libserver/url.c b/src/libserver/url.c index d774eb440..8ad073ae2 100644 --- a/src/libserver/url.c +++ b/src/libserver/url.c @@ -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 */ diff --git a/src/libstat/tokenizers/tokenizers.c b/src/libstat/tokenizers/tokenizers.c index caa4a48a5..b6061ce3b 100644 --- a/src/libstat/tokenizers/tokenizers.c +++ b/src/libstat/tokenizers/tokenizers.c @@ -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) { diff --git a/src/libutil/hash.c b/src/libutil/hash.c index c40200f64..56e80a17e 100644 --- a/src/libutil/hash.c +++ b/src/libutil/hash.c @@ -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 */ diff --git a/src/libutil/str_util.c b/src/libutil/str_util.c index d32a0d4d1..290110b2b 100644 --- a/src/libutil/str_util.c +++ b/src/libutil/str_util.c @@ -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 */ diff --git a/src/lua/lua_util.c b/src/lua/lua_util.c index 25fdc1514..ec5f98c22 100644 --- a/src/lua/lua_util.c +++ b/src/lua/lua_util.c @@ -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; } } -- 2.39.5