Fix problems found by static analyzing.
# 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})
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)
*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;
g_array_free (tmp, TRUE);
return -1;
}
- if (ses && sn) {
+ if (ses && sn && e) {
*sn = e->op ? ctx.si + 1 : 0;
}
else {
result->header = memory_pool_strdup (pool, line);
result->type = REGEXP_HEADER;
- line = begin;
+ line = start;
}
/* Find begin of regexp */
while (*line && *line != '/') {
time_t now;
struct tm *tms;
struct iovec iov[4];
- gint r;
+ gint r = 0;
guint32 cksum;
size_t mlen;
const gchar *cptype = NULL;
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
{
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 *
{
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;
}
{
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 *
{
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 *
{
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 *
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 ***/
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;
{
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
{
void *ud = luaL_checkudata (L, 1, "rspamd{message}");
luaL_argcheck (L, ud != NULL, 1, "'message' expected");
- return *((GMimeMessage **) ud);
+ return ud ? *((GMimeMessage **) ud) : NULL;
}
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
{
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 *
{
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 *
{
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 *
{
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 ***/
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;
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));
}
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++;
}
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;
}
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;
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;