From fd6c856b34c8fda53b7e45e3dcc17625206ed4fb Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Thu, 21 Jul 2011 17:35:29 +0400 Subject: [PATCH] Add workaround for clang under linux. Fix problems found by static analyzing. --- CMakeLists.txt | 9 +++++++-- src/cfg_xml.c | 2 +- src/diff.c | 2 +- src/expressions.c | 2 +- src/logger.c | 2 +- src/lua/lua_cdb.c | 2 +- src/lua/lua_classifier.c | 4 ++-- src/lua/lua_config.c | 10 +++++----- src/lua/lua_http.c | 2 +- src/lua/lua_message.c | 2 +- src/lua/lua_regexp.c | 2 +- src/lua/lua_task.c | 10 +++++----- src/mem_pool.c | 2 +- src/plugins/fuzzy_check.c | 2 +- src/plugins/regexp.c | 21 +++++++++++---------- src/plugins/surbl.c | 2 +- src/url.c | 6 ++++-- 17 files changed, 45 insertions(+), 37 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c048bd7d1..ebc2ee847 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -43,7 +43,6 @@ INCLUDE(FindPerl) # Initial set SET(CMAKE_REQUIRED_LIBRARIES m) -SET(CMAKE_REQUIRED_INCLUDES sys/mman.h stdlib.h stdio.h unistd.h time.h sched.h) IF(CMAKE_INSTALL_PREFIX) SET(PREFIX ${CMAKE_INSTALL_PREFIX}) @@ -127,7 +126,13 @@ IF(CMAKE_SYSTEM_NAME STREQUAL "Linux") IF(NOT MAN_PREFIX) SET(MAN_PREFIX /usr/share/man) ENDIF(NOT MAN_PREFIX) - ENDIF(CMAKE_INSTALL_PREFIX) + ENDIF(CMAKE_INSTALL_PREFIX) + + # Workaround with architecture specific includes + IF(IS_DIRECTORY "/usr/include/${CMAKE_SYSTEM_PROCESSOR}-linux-gnu/") + INCLUDE_DIRECTORIES("/usr/include/${CMAKE_SYSTEM_PROCESSOR}-linux-gnu/") + SET(CMAKE_REQUIRED_INCLUDES "/usr/include/${CMAKE_SYSTEM_PROCESSOR}-linux-gnu/") + ENDIF(IS_DIRECTORY "/usr/include/${CMAKE_SYSTEM_PROCESSOR}-linux-gnu/") LIST(APPEND CMAKE_REQUIRED_LIBRARIES rt) LIST(APPEND CMAKE_REQUIRED_LIBRARIES dl) diff --git a/src/cfg_xml.c b/src/cfg_xml.c index 9920f355c..27667649d 100644 --- a/src/cfg_xml.c +++ b/src/cfg_xml.c @@ -1611,7 +1611,7 @@ rspamd_xml_start_element (GMarkupParseContext *context, const gchar *element_nam *error = g_error_new (xml_error_quark (), XML_PARAM_MISSING, "param 'condition' is required for tag 'if'"); ud->state = XML_ERROR; } - if (! lua_check_condition (ud->cfg, condition)) { + else if (! lua_check_condition (ud->cfg, condition)) { ud->state = XML_SKIP_ELEMENTS; } return; diff --git a/src/diff.c b/src/diff.c index a2e84349b..45984ab38 100644 --- a/src/diff.c +++ b/src/diff.c @@ -342,7 +342,7 @@ rspamd_diff(const void *a, gint aoff, gint n, const void *b, gint boff, gint m, g_array_free (tmp, TRUE); return -1; } - if (ses && sn) { + if (ses && sn && e) { *sn = e->op ? ctx.si + 1 : 0; } diff --git a/src/expressions.c b/src/expressions.c index 396a5f6f1..a0bab2855 100644 --- a/src/expressions.c +++ b/src/expressions.c @@ -666,7 +666,7 @@ parse_regexp (memory_pool_t * pool, gchar *line, gboolean raw_mode) else { result->header = memory_pool_strdup (pool, line); result->type = REGEXP_HEADER; - line = begin; + line = start; } /* Find begin of regexp */ while (*line && *line != '/') { diff --git a/src/logger.c b/src/logger.c index 0d9f9c988..07b0eca34 100644 --- a/src/logger.c +++ b/src/logger.c @@ -456,7 +456,7 @@ file_log_function (const gchar * log_domain, const gchar *function, GLogLevelFla time_t now; struct tm *tms; struct iovec iov[4]; - gint r; + gint r = 0; guint32 cksum; size_t mlen; const gchar *cptype = NULL; diff --git a/src/lua/lua_cdb.c b/src/lua/lua_cdb.c index 24f6b205f..fbbc69359 100644 --- a/src/lua/lua_cdb.c +++ b/src/lua/lua_cdb.c @@ -49,7 +49,7 @@ lua_check_cdb (lua_State * L) void *ud = luaL_checkudata (L, 1, "rspamd{cdb}"); luaL_argcheck (L, ud != NULL, 1, "'cdb' expected"); - return *((struct cdb **)ud); + return ud ? *((struct cdb **)ud) : NULL; } static gint diff --git a/src/lua/lua_classifier.c b/src/lua/lua_classifier.c index 4e868b7f7..82fd4948d 100644 --- a/src/lua/lua_classifier.c +++ b/src/lua/lua_classifier.c @@ -72,7 +72,7 @@ lua_check_classifier (lua_State * L) { void *ud = luaL_checkudata (L, 1, "rspamd{classifier}"); luaL_argcheck (L, ud != NULL, 1, "'classifier' expected"); - return *((struct classifier_config **)ud); + return ud ? *((struct classifier_config **)ud) : NULL; } static GList * @@ -353,7 +353,7 @@ lua_check_statfile (lua_State * L) { void *ud = luaL_checkudata (L, 1, "rspamd{statfile}"); luaL_argcheck (L, ud != NULL, 1, "'statfile' expected"); - return *((struct statfile **)ud); + return ud ? *((struct statfile **)ud) : NULL; } diff --git a/src/lua/lua_config.c b/src/lua/lua_config.c index b4db951ff..d67176f0f 100644 --- a/src/lua/lua_config.c +++ b/src/lua/lua_config.c @@ -109,7 +109,7 @@ lua_check_config (lua_State * L) { void *ud = luaL_checkudata (L, 1, "rspamd{config}"); luaL_argcheck (L, ud != NULL, 1, "'config' expected"); - return *((struct config_file **)ud); + return ud ? *((struct config_file **)ud) : NULL; } static radix_tree_t * @@ -117,7 +117,7 @@ lua_check_radix (lua_State * L) { void *ud = luaL_checkudata (L, 1, "rspamd{radix}"); luaL_argcheck (L, ud != NULL, 1, "'radix' expected"); - return **((radix_tree_t ***)ud); + return ud ? **((radix_tree_t ***)ud) : NULL; } static GHashTable * @@ -125,7 +125,7 @@ lua_check_hash_table (lua_State * L) { void *ud = luaL_checkudata (L, 1, "rspamd{hash_table}"); luaL_argcheck (L, ud != NULL, 1, "'hash_table' expected"); - return **((GHashTable ***)ud); + return ud ? **((GHashTable ***)ud) : NULL; } static rspamd_trie_t * @@ -134,7 +134,7 @@ lua_check_trie (lua_State * L) void *ud = luaL_checkudata (L, 1, "rspamd{trie}"); luaL_argcheck (L, ud != NULL, 1, "'trie' expected"); - return *((rspamd_trie_t **)ud); + return ud ? *((rspamd_trie_t **)ud) : NULL; } /*** Config functions ***/ @@ -764,7 +764,7 @@ lua_trie_search_task (lua_State *L) if (trie) { ud = luaL_checkudata (L, 2, "rspamd{task}"); luaL_argcheck (L, ud != NULL, 1, "'task' expected"); - task = *((struct worker_task **)ud); + task = ud ? *((struct worker_task **)ud) : NULL; if (task) { lua_newtable (L); cur = task->text_parts; diff --git a/src/lua/lua_http.c b/src/lua/lua_http.c index 1ecfdfd12..99976c238 100644 --- a/src/lua/lua_http.c +++ b/src/lua/lua_http.c @@ -63,7 +63,7 @@ lua_check_task (lua_State * L) { void *ud = luaL_checkudata (L, 1, "rspamd{task}"); luaL_argcheck (L, ud != NULL, 1, "'task' expected"); - return *((struct worker_task **)ud); + return ud ? *((struct worker_task **)ud) : NULL; } static void diff --git a/src/lua/lua_message.c b/src/lua/lua_message.c index 70e33981b..1026c3690 100644 --- a/src/lua/lua_message.c +++ b/src/lua/lua_message.c @@ -94,7 +94,7 @@ lua_check_message (lua_State * L) { void *ud = luaL_checkudata (L, 1, "rspamd{message}"); luaL_argcheck (L, ud != NULL, 1, "'message' expected"); - return *((GMimeMessage **) ud); + return ud ? *((GMimeMessage **) ud) : NULL; } diff --git a/src/lua/lua_regexp.c b/src/lua/lua_regexp.c index ee8579dec..7a0b3d0c3 100644 --- a/src/lua/lua_regexp.c +++ b/src/lua/lua_regexp.c @@ -53,7 +53,7 @@ lua_check_regexp (lua_State * L) void *ud = luaL_checkudata (L, 1, "rspamd{regexp}"); luaL_argcheck (L, ud != NULL, 1, "'regexp' expected"); - return *((GRegex **)ud); + return ud ? *((GRegex **)ud) : NULL; } static int diff --git a/src/lua/lua_task.c b/src/lua/lua_task.c index a6530160f..f3fdc3bad 100644 --- a/src/lua/lua_task.c +++ b/src/lua/lua_task.c @@ -166,7 +166,7 @@ lua_check_task (lua_State * L) { void *ud = luaL_checkudata (L, 1, "rspamd{task}"); luaL_argcheck (L, ud != NULL, 1, "'task' expected"); - return *((struct worker_task **)ud); + return ud ? *((struct worker_task **)ud) : NULL; } static struct mime_text_part * @@ -174,7 +174,7 @@ lua_check_textpart (lua_State * L) { void *ud = luaL_checkudata (L, 1, "rspamd{textpart}"); luaL_argcheck (L, ud != NULL, 1, "'textpart' expected"); - return *((struct mime_text_part **)ud); + return ud ? *((struct mime_text_part **)ud) : NULL; } static struct rspamd_image * @@ -182,7 +182,7 @@ lua_check_image (lua_State * L) { void *ud = luaL_checkudata (L, 1, "rspamd{image}"); luaL_argcheck (L, ud != NULL, 1, "'image' expected"); - return *((struct rspamd_image **)ud); + return ud ? *((struct rspamd_image **)ud) : NULL; } static struct uri * @@ -190,7 +190,7 @@ lua_check_url (lua_State * L) { void *ud = luaL_checkudata (L, 1, "rspamd{url}"); luaL_argcheck (L, ud != NULL, 1, "'url' expected"); - return *((struct uri **)ud); + return ud ? *((struct uri **)ud) : NULL; } /*** Task interface ***/ @@ -1355,7 +1355,7 @@ lua_textpart_compare_distance (lua_State * L) const GMimeContentType *ct; luaL_argcheck (L, ud != NULL, 2, "'textpart' expected"); - other = *((struct mime_text_part **)ud); + other = ud ? *((struct mime_text_part **)ud) : NULL; if (part->parent && part->parent == other->parent) { parent = part->parent; diff --git a/src/mem_pool.c b/src/mem_pool.c index 43ffc86a0..32eb4d786 100644 --- a/src/mem_pool.c +++ b/src/mem_pool.c @@ -513,7 +513,7 @@ memory_pool_delete (memory_pool_t * pool) cur_shared = cur_shared->next; STAT_LOCK (); mem_pool_stat->chunks_freed++; - mem_pool_stat->bytes_allocated -= tmp->len; + mem_pool_stat->bytes_allocated -= tmp_shared->len; STAT_UNLOCK (); munmap ((void *)tmp_shared, tmp_shared->len + sizeof (struct _pool_chain_shared)); } diff --git a/src/plugins/fuzzy_check.c b/src/plugins/fuzzy_check.c index 93ba4bf25..eafbbeb90 100644 --- a/src/plugins/fuzzy_check.c +++ b/src/plugins/fuzzy_check.c @@ -271,7 +271,7 @@ parse_servers_string (gchar *str) else { fuzzy_module_ctx->servers[fuzzy_module_ctx->servers_num].port = port; fuzzy_module_ctx->servers[fuzzy_module_ctx->servers_num].name = name; - memcpy (&fuzzy_module_ctx->servers[fuzzy_module_ctx->servers_num].addr, hent->h_addr, sizeof (struct in_addr)); + memcpy (&fuzzy_module_ctx->servers[fuzzy_module_ctx->servers_num].addr, &addr, sizeof (struct in_addr)); fuzzy_module_ctx->servers_num++; } diff --git a/src/plugins/regexp.c b/src/plugins/regexp.c index d2e22a14a..89f1ed5c3 100644 --- a/src/plugins/regexp.c +++ b/src/plugins/regexp.c @@ -1427,23 +1427,24 @@ lua_regexp_match (lua_State *L) struct worker_task *task; const gchar *re_text; struct rspamd_regexp *re; - gint r; + gint r = 0; luaL_argcheck (L, ud != NULL, 1, "'task' expected"); - task = *((struct worker_task **)ud); + task = ud ? *((struct worker_task **)ud) : NULL; re_text = luaL_checkstring (L, 2); - /* This is a regexp */ - if ((re = re_cache_check (re_text, task->cfg->cfg_pool)) == NULL) { - re = parse_regexp (task->cfg->cfg_pool, (gchar *)re_text, task->cfg->raw_mode); - if (re == NULL) { - msg_warn ("cannot compile regexp for function"); - return FALSE; + if (task != NULL) { + if ((re = re_cache_check (re_text, task->cfg->cfg_pool)) == NULL) { + re = parse_regexp (task->cfg->cfg_pool, (gchar *)re_text, task->cfg->raw_mode); + if (re == NULL) { + msg_warn ("cannot compile regexp for function"); + return FALSE; + } + re_cache_add ((gchar *)re_text, re, task->cfg->cfg_pool); } - re_cache_add ((gchar *)re_text, re, task->cfg->cfg_pool); + r = process_regexp (re, task, NULL, 0, NULL); } - r = process_regexp (re, task, NULL, 0, NULL); lua_pushboolean (L, r == 1); return 1; diff --git a/src/plugins/surbl.c b/src/plugins/surbl.c index ba4559015..4e7194ed0 100644 --- a/src/plugins/surbl.c +++ b/src/plugins/surbl.c @@ -528,7 +528,7 @@ format_surbl_request (memory_pool_t * pool, f_str_t * hostname, struct suffix_it } else if (is_numeric && dots_num == 0) { /* This is number */ - if ((suffix->options & SURBL_OPTION_NOIP) != 0) { + if (suffix != NULL && (suffix->options & SURBL_OPTION_NOIP) != 0) { /* Ignore such requests */ msg_info ("ignore request of ip url for list %s", suffix->symbol); return NULL; diff --git a/src/url.c b/src/url.c index fd0459ff5..3ab8359a9 100644 --- a/src/url.c +++ b/src/url.c @@ -783,10 +783,12 @@ parse_uri (struct uri *uri, gchar *uristring, memory_pool_t * pool) prefix_end = host_end + 1; } - if (uri->ipv6) + if (uri->ipv6 && rbracket != NULL) { host_end = rbracket + strcspn (rbracket, ":/?"); - else + } + else { host_end = prefix_end + strcspn (prefix_end, ":/?"); + } if (uri->ipv6) { addrlen = rbracket - lbracket - 1; -- 2.39.5