hours = seconds / 3600;
minutes = seconds / 60 - hours * 60;
seconds -= hours * 3600 + minutes * 60;
- rspamd_printf ("%L hour%s %L minute%s %L second%s\n", hours,
- hours > 1 ? "s" : "", minutes,
- minutes > 1 ? "s" : "",
+ rspamd_printf ("%L hour %L minute%s %L second%s\n", hours,
+ minutes, minutes > 1 ? "s" : "",
seconds, seconds > 1 ? "s" : "");
}
}
else {
rspamd_printf_gstring (out, "Statfile: %s ", symbol);
}
- rspamd_printf_gstring (out, "length: %HL; free blocks: %HL; total blocks: %HL; "
- "free: %.2f%%; learned: %L\n", size, blocks - used_blocks, blocks,
- (blocks - used_blocks) * 100.0 / (gdouble)blocks, version);
+
+ if (blocks != 0) {
+ rspamd_printf_gstring (out, "length: %HL; free blocks: %HL; total blocks: %HL; "
+ "free: %.2f%%; learned: %L\n", size, blocks - used_blocks, blocks,
+ (blocks - used_blocks) * 100.0 / (gdouble)blocks, version);
+ }
}
static void
/* Read the whole buffer */
if (read (fd, reply->body->str, st.st_size) == -1) {
+ close (fd);
rspamd_http_message_free (reply);
msg_err ("cannot read map %s: %s", map->uri, strerror (errno));
rspamd_controller_send_error (conn_ent, 500, "500 map read error");
}
}
if (stack) {
- op = delete_expression_stack (&stack);
+ /* Remove open brace itself */
+ delete_expression_stack (&stack);
}
}
else if (*p == '(') {
if (result->regexp == NULL || err != NULL) {
msg_warn ("could not read regexp: %s while reading regexp %s",
- err->message,
+ err ? err->message : "unknown error",
src);
return NULL;
}
if (result->raw_regexp == NULL || err != NULL) {
msg_warn ("could not read raw regexp: %s while reading regexp %s",
- err->message,
+ err ? err->message : "unknown error",
src);
return NULL;
}
const ucl_object_t *ms = NULL;
int i;
- if (metric->actions != NULL) {
- if (task->settings) {
- ms = ucl_object_find_key (task->settings, metric->name);
- }
+ if (task->settings) {
+ ms = ucl_object_find_key (task->settings, metric->name);
+ }
- for (i = METRIC_ACTION_REJECT; i < METRIC_ACTION_MAX; i++) {
- double sc;
+ for (i = METRIC_ACTION_REJECT; i < METRIC_ACTION_MAX; i++) {
+ double sc;
- action = &metric->actions[i];
- sc = get_specific_action_score (ms, action);
+ action = &metric->actions[i];
+ sc = get_specific_action_score (ms, action);
- if (sc < 0) {
- continue;
- }
- if (score >= sc && sc > max_score) {
- selected_action = action;
- max_score = sc;
- }
+ if (sc < 0) {
+ continue;
+ }
+ if (score >= sc && sc > max_score) {
+ selected_action = action;
+ max_score = sc;
+ }
- if (rscore != NULL && i == METRIC_ACTION_REJECT) {
- *rscore = sc;
- }
+ if (rscore != NULL && i == METRIC_ACTION_REJECT) {
+ *rscore = sc;
}
}
+
if (selected_action) {
return selected_action->action;
}
return "BMP";
break;
default:
- return "unknown";
+ break;
}
return "unknown";
}
val = ucl_object_find_key (obj, "group");
if (val != NULL) {
- ucl_object_tostring_safe (val, &group);
+ group = ucl_object_tostring (val);
}
val = ucl_object_find_key (obj, "one_shot");
if (val != NULL) {
gchar *data;
GError *err = NULL;
struct rspamd_rcl_section *top, *logger;
- gboolean res;
struct ucl_parser *parser;
if (stat (filename, &st) == -1) {
munmap (data, st.st_size);
cfg->rcl_obj = ucl_parser_get_object (parser);
ucl_parser_free (parser);
- res = TRUE;
-
- if (!res) {
- return FALSE;
- }
top = rspamd_rcl_config_init ();
err = NULL;
}
if (stat (cfg->cfg_name, &st) == -1) {
msg_err ("cannot stat %s: %s", cfg->cfg_name, strerror (errno));
+ close (fd);
return FALSE;
}
clock_getres (CLOCK_REALTIME, &ts);
# endif
- cfg->clock_res = (gint)log10 (1000000 / ts.tv_nsec);
+ cfg->clock_res = log10 (1000000. / ts.tv_nsec);
if (cfg->clock_res < 0) {
cfg->clock_res = 0;
}
dir = g_path_get_dirname (cfg->dynamic_conf);
if (dir == NULL) {
- /* Inaccessible path */
- if (dir != NULL) {
- g_free (dir);
- }
- msg_err ("invalid file: %s", cfg->dynamic_conf);
+ msg_err ("invalid path: %s", cfg->dynamic_conf);
return FALSE;
}
}
}
+ close (fd);
+
/* Open database */
if ((res = rspamd_fuzzy_backend_open_db (path, err)) == NULL) {
GError *tmp = NULL;
/* Check whether this item is skipped */
skipped = TRUE;
- if (!item->is_callback &&
+ if (!item->is_callback && pcache->cfg &&
g_hash_table_lookup (pcache->cfg->metrics_symbols, name) == NULL) {
cur = g_list_first (pcache->cfg->metrics_list);
while (cur) {
if (lseek (fd, -(cklen), SEEK_END) == -1) {
if (errno == EINVAL) {
/* Try to create file */
+ close (fd);
msg_info ("recreate cache file");
if ((fd =
open (filename, O_RDWR | O_TRUNC | O_CREAT, S_IWUSR |
new = rspamd_mmaped_file_open (pool, filename, size, stcf);
if (fd == -1 || new == NULL) {
+ if (fd != -1) {
+ close (fd);
+ }
+
msg_err ("cannot open file: %s", strerror (errno));
g_free (backup);
return NULL;
const struct in6_addr ip6_local = IN6ADDR_LOOPBACK_INIT;
s = socket (AF_INET6, SOCK_STREAM, 0);
- if (s == -1 && errno == EAFNOSUPPORT) {
+ if (s == -1) {
ipv6_status = RSPAMD_IPV6_UNSUPPORTED;
}
else {
* - |
*/
+ /*
+ * XXX: coverity found this code suspicious, needs checking
+ */
if (m > n) {
if (x == u) {
_edit (ctx, DIFF_MATCH, aoff, n);
{
struct _ctx ctx;
gint d, x, y;
- struct diff_edit *e = NULL;
GArray *tmp;
tmp = g_array_sized_new (FALSE, TRUE, sizeof(gint), dmax);
g_array_free (tmp, TRUE);
return -1;
}
- if (ses && sn && e) {
- *sn = e->op ? ctx.si + 1 : 0;
- }
g_array_free (tmp, TRUE);
return d;
{
size_t i;
guint32 hval;
- gchar *c = str->begin;
+ gchar *c;
if (str == NULL) {
return 0;
}
+ c = str->begin;
hval = str->len;
for (i = 0; i < str->len; i++, c++) {
{
gsize i;
guint32 j, hval;
- const gchar *p = str->begin, *end = NULL;
+ const gchar *p, *end = NULL;
gchar t;
gunichar uc;
if (str == NULL) {
return 0;
}
+
+ p = str->begin;
hval = str->len;
if (is_utf) {
if (elt->hash && elt->hash->value_destroy) {
elt->hash->value_destroy (elt->data);
}
- if (elt->link) {
+ if (elt->hash && elt->link) {
g_queue_delete_link (elt->hash->exp, elt->link);
}
rspamd_inet_socket_create (gint type, struct addrinfo *addr, gboolean is_server,
gboolean async, GList **list)
{
- gint fd, r, optlen, on = 1, s_error;
+ gint fd = -1, r, optlen, on = 1, s_error;
struct addrinfo *cur;
cur = addr;
struct sockaddr_un un;
struct stat st;
struct addrinfo hints, *res;
- gint r, fd, serrno;
+ gint r, fd = -1, serrno;
gchar portbuf[8], **strv, **cur;
GList *result = NULL, *rcur;
rspamd_snprintf (portbuf, sizeof (portbuf), "%d", (int)port);
if ((r = getaddrinfo (credits, portbuf, &hints, &res)) == 0) {
- r = rspamd_inet_socket_create (type, res, is_server, async, &result);
+ fd = rspamd_inet_socket_create (type, res, is_server, async, &result);
freeaddrinfo (res);
+
if (result == NULL) {
+ if (fd != -1) {
+ close (fd);
+ }
+
goto err;
}
}
goto err;
}
}
+
cur++;
}
lua_io_dispatcher_set_policy (lua_State *L)
{
struct rspamd_io_dispatcher_s *io_dispatcher = lua_check_io_dispatcher (L);
- gint policy, limit = -1;
+ gint policy, limit = 0;
if (io_dispatcher) {
policy = lua_tonumber (L, 2);
{
struct lua_callback_data *cd;
- cd = rspamd_mempool_alloc0 (cfg->cfg_pool,
- sizeof (struct lua_callback_data));
- cd->cb_is_ref = TRUE;
- cd->callback.ref = ref;
- cd->L = L;
if (name) {
+ cd = rspamd_mempool_alloc0 (cfg->cfg_pool,
+ sizeof (struct lua_callback_data));
+ cd->cb_is_ref = TRUE;
+ cd->callback.ref = ref;
+ cd->L = L;
cd->symbol = rspamd_mempool_strdup (cfg->cfg_pool, name);
+
+ register_symbol_common (&cfg->cache,
+ name,
+ weight,
+ priority,
+ lua_metric_symbol_callback,
+ cd,
+ type);
+ rspamd_mempool_add_destructor (cfg->cfg_pool,
+ (rspamd_mempool_destruct_t)lua_destroy_cfg_symbol,
+ cd);
}
- register_symbol_common (&cfg->cache,
- name,
- weight,
- priority,
- lua_metric_symbol_callback,
- cd,
- type);
- rspamd_mempool_add_destructor (cfg->cfg_pool,
- (rspamd_mempool_destruct_t)lua_destroy_cfg_symbol,
- cd);
+
}
static gint
name = luaL_checkstring (L, 2);
- if (name != NULL && lua_gettop (L) > 2) {
+ if (cfg != NULL && name != NULL && lua_gettop (L) > 2) {
if (lua_type (L, 3) == LUA_TFUNCTION) {
/* Normal symbol from just a function */
lua_pushvalue (L, 3);
gboolean found = FALSE;
if (trie) {
- text = luaL_checkstring (L, 2);
- len = strlen (text);
+ text = luaL_checklstring (L, 2, &len);
if (text) {
lua_newtable (L);
pos = text;
guint32 umsk, *p;
mask = lua_tonumber (L, 2);
- if (mask > 0 && ip->is_valid) {
+ if (mask > 0 && ip != NULL && ip->is_valid) {
if (ip->addr.af == AF_INET && mask <= 32) {
nip = lua_ip_new (L, ip);
umsk = htonl (G_MAXUINT32 << (32 - mask));
*ip2 = lua_check_ip (L, 2);
gboolean res = FALSE;
- if (ip1->is_valid && ip2->is_valid) {
+ if (ip1 && ip2 && ip1->is_valid && ip2->is_valid) {
if (ip1->addr.af == ip2->addr.af) {
if (ip1->addr.af == AF_INET) {
if (memcmp(&ip1->addr.addr.s4.sin_addr,