sa = &addr->u.in.addr.sa;
}
- setsockopt (fd, SOL_SOCKET, SO_REUSEADDR, (const void *)&on, sizeof (gint));
+ (void)setsockopt (fd, SOL_SOCKET, SO_REUSEADDR, (const void *)&on, sizeof (gint));
#ifdef HAVE_IPV6_V6ONLY
if (addr->af == AF_INET6) {
/* We need to set this flag to avoid errors */
on = 1;
#ifdef SOL_IPV6
- setsockopt (fd, SOL_IPV6, IPV6_V6ONLY, (const void *)&on, sizeof (gint));
+ (void)setsockopt (fd, SOL_IPV6, IPV6_V6ONLY, (const void *)&on, sizeof (gint));
#elif defined(IPPROTO_IPV6)
- setsockopt (fd, IPPROTO_IPV6, IPV6_V6ONLY, (const void *)&on, sizeof (gint));
+ (void)setsockopt (fd, IPPROTO_IPV6, IPV6_V6ONLY, (const void *)&on, sizeof (gint));
#endif
}
#endif
msg->body_buf.len = 0;
+ memset (&decrypted_parser, 0, sizeof (decrypted_parser));
http_parser_init (&decrypted_parser,
conn->type == RSPAMD_HTTP_SERVER ? HTTP_REQUEST : HTTP_RESPONSE);
c = p;
data->state = 1;
}
- else if (*p == '\r' || *p == '\n') {
+ else if ((*p == '\r' || *p == '\n') && p > c) {
/* Got EOL marker, save stored string */
s = strip_map_elt (pool, c, p - c);
path, rc);
#endif
+ if (has_lock && lock_fd != -1) {
+ msg_debug_pool_check ("removing lock from %s", lock_path);
+ rspamd_file_unlock (lock_fd, FALSE);
+ unlink (lock_path);
+ close (lock_fd);
+ }
+
return NULL;
}
sqlite3_errmsg (sqlite));
}
- if (has_lock) {
+ if (has_lock && lock_fd != -1) {
msg_debug_pool_check ("removing lock from %s", lock_path);
rspamd_file_unlock (lock_fd, FALSE);
unlink (lock_path);
rspamd_decode_hex_buf (const gchar *in, gsize inlen,
guchar *out, gsize outlen)
{
- guchar *o, *end, ret;
+ guchar *o, *end, ret = 0;
const gchar *p;
gchar c;
}
if (is_server) {
- setsockopt (fd,
- SOL_SOCKET,
- SO_REUSEADDR,
- (const void *)&on,
- sizeof (gint));
+ if (setsockopt (fd,
+ SOL_SOCKET,
+ SO_REUSEADDR,
+ (const void *)&on,
+ sizeof (gint)) == -1) {
+ msg_warn ("setsockopt failed: %d, '%s'", errno,
+ strerror (errno));
+ }
#ifdef HAVE_IPV6_V6ONLY
if (cur->ai_family == AF_INET6) {
- setsockopt (fd,
- IPPROTO_IPV6,
- IPV6_V6ONLY,
- (const void *)&on,
- sizeof (gint));
+ if (setsockopt (fd,
+ IPPROTO_IPV6,
+ IPV6_V6ONLY,
+ (const void *)&on,
+ sizeof (gint)) == -1) {
+
+ msg_warn ("setsockopt failed: %d, '%s'", errno,
+ strerror (errno));
+ }
}
#endif
r = bind (fd, cur->ai_addr, cur->ai_addrlen);
else {
/* Still need to check SO_ERROR on socket */
optlen = sizeof (s_error);
- getsockopt (fd, SOL_SOCKET, SO_ERROR, (void *)&s_error, &optlen);
- if (s_error) {
- errno = s_error;
- goto out;
+
+ if (getsockopt (fd, SOL_SOCKET, SO_ERROR, (void *)&s_error, &optlen) != -1) {
+ if (s_error) {
+ errno = s_error;
+ goto out;
+ }
}
}
if (list == NULL) {
goto out;
}
if (is_server) {
- setsockopt (fd, SOL_SOCKET, SO_REUSEADDR, (const void *)&on,
- sizeof (gint));
+ if (setsockopt (fd, SOL_SOCKET, SO_REUSEADDR, (const void *)&on,
+ sizeof (gint)) == -1) {
+ msg_warn ("setsockopt failed: %d, '%s'", errno,
+ strerror (errno));
+ }
+
r = bind (fd, (struct sockaddr *)addr, SUN_LEN (addr));
}
else {
else {
/* Still need to check SO_ERROR on socket */
optlen = sizeof (s_error);
- getsockopt (fd, SOL_SOCKET, SO_ERROR, (void *)&s_error, &optlen);
- if (s_error) {
- errno = s_error;
- goto out;
+
+ if (getsockopt (fd, SOL_SOCKET, SO_ERROR, (void *)&s_error, &optlen) != -1) {
+ if (s_error) {
+ errno = s_error;
+ goto out;
+ }
}
}
}
if (fd != -1) {
result = g_list_prepend (result, GINT_TO_POINTER (fd));
+ fd = -1;
}
else {
goto err;
/* Turn echo off */
if (tcgetattr (input, &oterm) != 0) {
+ close (input);
errno = ENOTTY;
return 0;
}
+
memcpy (&term, &oterm, sizeof(term));
term.c_lflag &= ~(ECHO | ECHONL);
- (void)tcsetattr (input, TCSAFLUSH, &term);
+
+ if (tcsetattr (input, TCSAFLUSH, &term) == -1) {
+ errno = ENOTTY;
+ close (input);
+ return 0;
+ }
+
(void)write (output, "Enter passphrase: ", sizeof ("Enter passphrase: ") -
1);
}
}
- return p - buf;
+ return (p - buf);
#endif
}
OTTERY_ENTROPY_SRC_RDRAND);
}
- ottery_init (ottery_cfg);
+ g_assert (ottery_init (ottery_cfg) == 0);
#ifdef HAVE_LOCALE_H
if (getenv ("LANG") == NULL) {
cd->callback.ref = luaL_ref (L, LUA_REGISTRYINDEX);
cd->cb_is_ref = TRUE;
}
+
cd->L = L;
cfg->pre_filters = g_list_prepend (cfg->pre_filters, cd);
rspamd_mempool_add_destructor (cfg->cfg_pool,
description = lua_tostring (L, 3);
r = rspamd_mempool_alloc (cfg->cfg_pool, sizeof (radix_compressed_t *));
*r = radix_create_compressed ();
+
if (!rspamd_map_add (cfg, map_line, description, rspamd_radix_read,
rspamd_radix_fin, (void **)r)) {
msg_warn_config ("invalid radix map %s", map_line);
lua_pushnil (L);
return 1;
}
- ud = lua_newuserdata (L, sizeof (radix_compressed_t *));
+
+ ud = lua_newuserdata (L, sizeof (radix_compressed_t **));
*ud = r;
rspamd_lua_setclass (L, "rspamd{radix}", -1);
r = rspamd_mempool_alloc (cfg->cfg_pool, sizeof (radix_compressed_t *));
*r = radix_create_compressed ();
radix_add_generic_iplist (ucl_obj_tostring (obj), r);
- ud = lua_newuserdata (L, sizeof (radix_compressed_t *));
+ ud = lua_newuserdata (L, sizeof (radix_compressed_t **));
*ud = r;
rspamd_lua_setclass (L, "rspamd{radix}", -1);
return 1;
description = lua_tostring (L, 3);
r = rspamd_mempool_alloc (cfg->cfg_pool, sizeof (GHashTable *));
*r = g_hash_table_new (rspamd_strcase_hash, rspamd_strcase_equal);
+
if (!rspamd_map_add (cfg, map_line, description, rspamd_hosts_read, rspamd_hosts_fin,
(void **)r)) {
msg_warn ("invalid hash map %s", map_line);
lua_pushnil (L);
return 1;
}
+
rspamd_mempool_add_destructor (cfg->cfg_pool,
(rspamd_mempool_destruct_t)g_hash_table_destroy,
*r);
- ud = lua_newuserdata (L, sizeof (GHashTable *));
+ ud = lua_newuserdata (L, sizeof (GHashTable **));
*ud = r;
rspamd_lua_setclass (L, "rspamd{hash_table}", -1);
description = lua_tostring (L, 3);
r = rspamd_mempool_alloc (cfg->cfg_pool, sizeof (GHashTable *));
*r = g_hash_table_new (rspamd_strcase_hash, rspamd_strcase_equal);
+
if (!rspamd_map_add (cfg, map_line, description, rspamd_kv_list_read, rspamd_kv_list_fin,
(void **)r)) {
msg_warn_config ("invalid hash map %s", map_line);
lua_pushnil (L);
return 1;
}
+
rspamd_mempool_add_destructor (cfg->cfg_pool,
(rspamd_mempool_destruct_t)g_hash_table_destroy,
*r);
- ud = lua_newuserdata (L, sizeof (GHashTable *));
+ ud = lua_newuserdata (L, sizeof (GHashTable **));
*ud = r;
rspamd_lua_setclass (L, "rspamd{hash_table}", -1);
gdouble weight = 1.0;
if (lua_gettop (L) < 3) {
- msg_err_config ("not enough arguments to register a function");
+ if (cfg) {
+ msg_err_config ("not enough arguments to register a function");
+ }
+
+ lua_error (L);
+
return 0;
}
if (cfg) {
const gchar *name = NULL, *from = NULL;
gint id;
+ if (cfg == NULL) {
+ lua_error (L);
+ return 0;
+ }
+
if (lua_type (L, 2) == LUA_TNUMBER) {
id = luaL_checknumber (L, 2);
name = luaL_checkstring (L, 3);
msg_err ("http request has bad params");
lua_pushboolean (L, FALSE);
- if (mime_type) {
- g_free (mime_type);
- }
-
return 1;
}
cbd->mime_type = mime_type;
msec_to_tv (timeout, &cbd->tv);
cbd->fd = -1;
+
if (session) {
cbd->session = session;
rspamd_session_add_event (session,
ip_str = luaL_checkstring (L, 1);
if (ip_str) {
ip = lua_ip_new (L, NULL);
- rspamd_parse_inet_address (&ip->addr, ip_str, 0);
+
+ if (!rspamd_parse_inet_address (&ip->addr, ip_str, 0)) {
+ msg_warn ("cannot parse ip: %s", ip_str);
+ }
}
else {
lua_pushnil (L);
}
else {
ip = g_slice_alloc0 (sizeof (struct rspamd_lua_ip));
- rspamd_parse_inet_address (&ip->addr, ip_str, 0);
- pip = lua_newuserdata (L, sizeof (struct rspamd_lua_ip *));
- rspamd_lua_setclass (L, "rspamd{ip}", -1);
- *pip = ip;
+ if (rspamd_parse_inet_address (&ip->addr, ip_str, 0)) {
+
+ pip = lua_newuserdata (L, sizeof (struct rspamd_lua_ip *));
+ rspamd_lua_setclass (L, "rspamd{ip}", -1);
+ *pip = ip;
+ }
+ else {
+ g_slice_free1 (sizeof (*ip), ip);
+ lua_pushnil (L);
+ }
}
}
}
else if (lua_type (L, 1) == LUA_TUSERDATA) {
fmt_pos = 2;
- lua_getmetatable (L, 1);
- lua_pushstring (L, "__index");
- lua_gettable (L, -2);
- lua_pushstring (L, "class");
- lua_gettable (L, -2);
+ if (lua_getmetatable (L, 1) != 0) {
+ lua_pushstring (L, "__index");
+ lua_gettable (L, -2);
- clsname = lua_tostring (L, -1);
+ lua_pushstring (L, "class");
+ lua_gettable (L, -2);
- if (strcmp (clsname, "rspamd{task}") == 0) {
- struct rspamd_task *task = lua_check_task (L, 1);
+ clsname = lua_tostring (L, -1);
- if (task) {
- uid = task->task_pool->tag.uid;
+ if (strcmp (clsname, "rspamd{task}") == 0) {
+ struct rspamd_task *task = lua_check_task (L, 1);
+
+ if (task) {
+ uid = task->task_pool->tag.uid;
+ }
}
- }
- else if (strcmp (clsname, "rspamd{mempool}") == 0) {
- rspamd_mempool_t *pool;
+ else if (strcmp (clsname, "rspamd{mempool}") == 0) {
+ rspamd_mempool_t *pool;
- pool = rspamd_lua_check_mempool (L, 1);
+ pool = rspamd_lua_check_mempool (L, 1);
- if (pool) {
- uid = pool->tag.uid;
+ if (pool) {
+ uid = pool->tag.uid;
+ }
}
- }
- else if (strcmp (clsname, "rspamd{config}") == 0) {
- struct rspamd_config *cfg;
+ else if (strcmp (clsname, "rspamd{config}") == 0) {
+ struct rspamd_config *cfg;
- cfg = lua_check_config (L, 1);
+ cfg = lua_check_config (L, 1);
- if (cfg) {
- uid = cfg->checksum;
+ if (cfg) {
+ uid = cfg->checksum;
+ }
}
+
+ /* Metatable, __index, classname */
+ lua_pop (L, 3);
}
+ else {
+ lua_error (L);
- /* Metatable, __index, classname */
- lua_pop (L, 3);
+ return 0;
+ }
}
else {
/* Bad argument type */
msg_err ("bad format string type: %s", lua_typename (L, lua_type (L,
1)));
+ lua_error (L);
+
return 0;
}
ud->terminated = 0;
ud->ctx = redisAsyncConnect (rspamd_inet_address_to_string (addr->addr),
rspamd_inet_address_get_port (addr->addr));
- redisAsyncSetConnectCallback (ud->ctx, lua_redis_connect_cb);
if (ud->ctx == NULL || ud->ctx->err) {
if (ud->ctx) {
return 1;
}
+ redisAsyncSetConnectCallback (ud->ctx, lua_redis_connect_cb);
redisLibeventAttach (ud->ctx, ud->task->ev_base);
ret = redisAsyncCommandArgv (ud->ctx,
lua_redis_callback,
ud->terminated = 0;
ud->ctx = redisAsyncConnect (rspamd_inet_address_to_string (addr->addr),
rspamd_inet_address_get_port (addr->addr));
- redisAsyncSetConnectCallback (ud->ctx, lua_redis_connect_cb);
if (ud->ctx == NULL || ud->ctx->err) {
REF_RELEASE (ctx);
return 1;
}
+ redisAsyncSetConnectCallback (ud->ctx, lua_redis_connect_cb);
redisLibeventAttach (ud->ctx, ud->task->ev_base);
pctx = lua_newuserdata (L, sizeof (ctx));
*pctx = ctx;
}
else if (lua_type (L, 2) == LUA_TUSERDATA) {
t = lua_check_text (L, 2);
+
+ if (t == NULL) {
+ lua_error (L);
+ return 0;
+ }
+
data = t->start;
len = t->len;
is_text = TRUE;
struct rspamd_task *task = lua_check_task (L, 1);
struct rspamd_config **pcfg;
- pcfg = lua_newuserdata (L, sizeof (gpointer));
- rspamd_lua_setclass (L, "rspamd{config}", -1);
- *pcfg = task->cfg;
+ if (task) {
+ pcfg = lua_newuserdata (L, sizeof (gpointer));
+ rspamd_lua_setclass (L, "rspamd{config}", -1);
+ *pcfg = task->cfg;
+ }
+ else {
+ lua_error (L);
+ }
return 1;
}
struct rspamd_task *task = lua_check_task (L, 1);
void *ud = luaL_checkudata (L, 2, "rspamd{config}");
- luaL_argcheck (L, ud != NULL, 1, "'config' expected");
- task->cfg = ud ? *((struct rspamd_config **)ud) : NULL;
+ if (task) {
+ luaL_argcheck (L, ud != NULL, 1, "'config' expected");
+ task->cfg = ud ? *((struct rspamd_config **)ud) : NULL;
+ }
+ else {
+ lua_error (L);
+ }
+
return 0;
}
s = luaL_checklstring (L, 2, &len);
- if (s) {
+ if (s && task) {
if (lua_type (L, 3) == LUA_TSTRING) {
v = luaL_checklstring (L, 2, &vlen);
}
GError *err = NULL;
int ret = 1;
+ if (task == NULL) {
+ lua_error (L);
+ return 0;
+ }
+
is_spam = lua_toboolean(L, 2);
if (lua_gettop (L) > 2) {
clname = luaL_checkstring (L, 3);
ucl_object_t *settings;
settings = ucl_object_lua_import (L, 2);
- if (settings != NULL) {
+ if (settings != NULL && task != NULL) {
task->settings = settings;
}
{
struct rspamd_task *task = lua_check_task (L, 1);
- msg_err_task ("this function is deprecated and will return nothing");
+ if (task) {
+ msg_err_task ("this function is deprecated and will return nothing");
+ }
+
lua_pushnumber (L, -1);
return 1;
{
struct rspamd_task *task = lua_check_task (L, 1);
- msg_err_task ("this function is deprecated and will return nothing");
+ if (task) {
+ msg_err_task ("this function is deprecated and will return nothing");
+ }
+
lua_pushnumber (L, 0);
return 1;
{
struct lua_trie_cbdata cb;
gboolean icase = FALSE;
+ gint ret;
if (lua_gettop (L) == 4) {
icase = lua_toboolean (L, 4);
cb.L = L;
cb.found = FALSE;
- acism_lookup (trie, str, len,
- lua_trie_callback, &cb, statep, icase);
- return cb.found;
+ if ((ret = acism_lookup (trie, str, len,
+ lua_trie_callback, &cb, statep, icase)) == 0) {
+ return cb.found;
+ }
+
+ return ret;
}
/***
guint default_port = 0;
def = luaL_checkstring (L, 2);
- if (def) {
+ if (def && cfg) {
if (lua_gettop (L) >= 3) {
default_port = luaL_checknumber (L, 3);
}
lua_pushnil (L);
}
}
+ else {
+ lua_error (L);
+ }
return 1;
}
}
rspamd_inet_address_destroy (addr);
+ close (nfd);
}
static gboolean
}
}
- if (all_done && res != NULL) {
+ if (all_done) {
rspamd_session_watcher_pop (res->task->s, res->w);
}
}
if ((value = ucl_object_find_key (obj, "servers")) != NULL) {
rule->servers = rspamd_upstreams_create (cfg->ups_ctx);
+
rspamd_mempool_add_destructor (fuzzy_module_ctx->fuzzy_pool,
(rspamd_mempool_destruct_t)rspamd_upstreams_destroy,
rule->servers);
- rspamd_upstreams_from_ucl (rule->servers, value, DEFAULT_PORT, NULL);
+ if (!rspamd_upstreams_from_ucl (rule->servers, value, DEFAULT_PORT, NULL)) {
+ msg_err_config ("cannot read servers definition");
+ return -1;
+ }
}
if ((value = ucl_object_find_key (obj, "fuzzy_map")) != NULL) {
it = NULL;
if (*session->saved > 0 ) {
(*session->saved)--;
- if (*session->saved == 0 && session->task != NULL) {
+ if (*session->saved == 0) {
rspamd_task_free (session->task);
session->task = NULL;
}
saved, err);
}
- if (res) {
+ if (res > 0) {
processed = TRUE;
}
else if (res == -1) {
if ((value =
rspamd_config_get_module_opt (cfg, "surbl",
"redirector_hosts_map")) != NULL) {
- rspamd_map_add (cfg, ucl_obj_tostring (
- value),
+ if (!rspamd_map_add (cfg, ucl_obj_tostring (value),
"SURBL redirectors list", read_redirectors_list, fin_redirectors_list,
- (void **)&surbl_module_ctx->redirector_map_data);
+ (void **)&surbl_module_ctx->redirector_map_data)) {
+
+ msg_warn_config ("bad redirectors map definition: %s",
+ ucl_obj_tostring (value));
+ }
}
if ((value =
rspamd_cryptobox_signature_bytes (mode));
rspamd_cryptobox_sign (sig, NULL, map, st.st_size, sk, mode);
- write (fd_sig, sig, rspamd_cryptobox_signature_bytes (mode));
+ g_assert (write (fd_sig, sig, rspamd_cryptobox_signature_bytes (mode)) != -1);
close (fd_sig);
munmap (map, st.st_size);