rspamd_symcache_set_allowed_settings_ids (cfg->cache, name,
ids, nids);
-
- g_free (ids);
}
+
+ g_free (ids);
}
if (forbidden_ids) {
rspamd_symcache_set_forbidden_settings_ids (cfg->cache, name,
ids, nids);
-
- g_free (ids);
}
+
+ g_free (ids);
}
return ret;
rspamd_symcache_init (cfg->cache);
}
else {
+ int ret = luaL_error (L, "invalid param: %s", parts[i]);
g_strfreev (parts);
- return luaL_error (L, "invalid param: %s", parts[i]);
+ return ret;
}
}
alg = RSPAMD_CRYPTOBOX_MODE_25519;
}
else {
+ munmap (data, st.st_size);
+ close (fd);
+
return luaL_error (L, "invalid keypair algorithm: %s", str);
}
}
t = lua_check_text (L, 1);
if (!t) {
+ REF_RELEASE (h);
return luaL_error (L, "invalid arguments");
}
t = lua_check_text (L, 2);
if (!t) {
+ REF_RELEASE (h);
return luaL_error (L, "invalid arguments");
}
t = lua_check_text (L, 2);
if (!t) {
+ REF_RELEASE (h);
return luaL_error (L, "invalid arguments");
}
if (key != NULL && type != NULL) {
h = rspamd_lua_hash_create (type, key, keylen);
+ if (h == NULL) {
+ return luaL_error (L, "invalid hash type: %s", type);
+ }
+
if (lua_type (L, 3) == LUA_TSTRING) {
s = lua_tolstring (L, 3, &len);
}
t = lua_check_text (L, 3);
if (!t) {
+ REF_RELEASE (h);
+
return luaL_error (L, "invalid arguments");
}
struct rspamd_lua_text *t, *res;
gsize len = 0, outlen = 0;
GError *err = NULL;
+ bool owned_pk = false;
if (lua_type (L, 1) == LUA_TUSERDATA) {
if (rspamd_lua_check_udata_maybe (L, 1, "rspamd{cryptobox_keypair}")) {
pk = rspamd_pubkey_from_base32 (b32, blen, RSPAMD_KEYPAIR_KEX,
lua_toboolean (L, 3) ?
RSPAMD_CRYPTOBOX_MODE_NIST : RSPAMD_CRYPTOBOX_MODE_25519);
+ owned_pk = true;
}
if (lua_isuserdata (L, 2)) {
t = lua_check_text (L, 2);
if (!t) {
- return luaL_error (L, "invalid arguments");
+ goto err;
}
data = t->start;
if (!(kp || pk) || !data) {
- return luaL_error (L, "invalid arguments");
+ goto err;
}
if (kp) {
return ret;
}
}
- else if (pk) {
+ else {
if (!rspamd_pubkey_encrypt (pk, data, len, &out, &outlen, &err)) {
gint ret = luaL_error (L, "cannot encrypt data: %s", err->message);
g_error_free (err);
res->len = outlen;
rspamd_lua_setclass (L, "rspamd{text}", -1);
+ if (owned_pk) {
+ rspamd_pubkey_unref (pk);
+ }
+
return 1;
+err:
+
+ if (owned_pk) {
+ rspamd_pubkey_unref (pk);
+ }
+
+ return luaL_error (L, "invalid arguments");
}
/***
struct rspamd_lua_text *res;
gsize len = 0, outlen = 0;
GError *err = NULL;
+ bool own_pk = false;
if (lua_type (L, 1) == LUA_TUSERDATA) {
if (rspamd_lua_check_udata_maybe (L, 1, "rspamd{cryptobox_keypair}")) {
pk = rspamd_pubkey_from_base32 (b32, blen, RSPAMD_KEYPAIR_KEX,
lua_toboolean (L, 3) ?
RSPAMD_CRYPTOBOX_MODE_NIST : RSPAMD_CRYPTOBOX_MODE_25519);
+ own_pk = true;
}
filename = luaL_checkstring (L, 2);
data = rspamd_file_xmap (filename, PROT_READ, &len, TRUE);
if (!(kp || pk) || !data) {
- return luaL_error (L, "invalid arguments");
+ goto err;
}
if (kp) {
res->len = outlen;
rspamd_lua_setclass (L, "rspamd{text}", -1);
munmap (data, len);
+ if (own_pk) {
+ rspamd_pubkey_unref (pk);
+ }
return 1;
+
+err:
+ if (own_pk) {
+ rspamd_pubkey_unref (pk);
+ }
+ return luaL_error (L, "invalid arguments");
}
/***
GError *err = NULL;
kp = lua_check_cryptobox_keypair (L, 1);
+ if (!kp) {
+ return luaL_error (L, "invalid arguments; keypair is expected");
+ }
+
filename = luaL_checkstring (L, 2);
data = rspamd_file_xmap (filename, PROT_READ, &len, TRUE);
-
-
- if (!kp || !data) {
- return luaL_error (L, "invalid arguments");
+ if (!data) {
+ return luaL_error (L, "invalid arguments; cannot mmap %s: %s",
+ filename, strerror(errno));
}
if (!rspamd_keypair_decrypt (kp, data, len, &out, &outlen, &err)) {
if (pwlen == 0) {
lua_pushnil (L);
+ g_free (password);
return 1;
}
}
return 1;
+
err:
+ /* Callback is not called in this case */
+ if (cbdata->cbref != -1) {
+ luaL_unref (L, LUA_REGISTRYINDEX, cbdata->cbref);
+ }
+
if (!pool) {
/* Free resources */
g_free (cbdata->to_resolve);
g_free (cbdata->user_str);
- }
-
- /* Callback is not called in this case */
- if (cbdata->cbref != -1) {
- luaL_unref (L, LUA_REGISTRYINDEX, cbdata->cbref);
+ g_free (cbdata);
}
lua_pushnil (L);
struct lua_html_tag *ltag = lua_check_html_tag (L, 1);
gint i = 1;
- if (ltag->tag) {
+ if (ltag && ltag->tag) {
/* Push flags */
lua_createtable (L, 4, 0);
if (ltag->tag->flags & FL_HREF) {
if (cbd->task) {
cbd->conn->log_tag = cbd->task->task_pool->tag.uid;
+
+ if (cbd->item) {
+ rspamd_symcache_item_async_inc (cbd->task, cbd->item, M);
+ }
}
else if (cbd->cfg) {
cbd->conn->log_tag = cbd->cfg->cfg_pool->tag.uid;
}
- if (cbd->item) {
- rspamd_symcache_item_async_inc (cbd->task, cbd->item, M);
- }
-
struct rspamd_http_message *msg = cbd->msg;
/* Message is now owned by a connection object */
if (lua_type (L, -1) == LUA_TUSERDATA) {
task = lua_check_task (L, -1);
- ev_base = task->event_loop;
- resolver = task->resolver;
- session = task->s;
- cfg = task->cfg;
+
+ if (task) {
+ ev_base = task->event_loop;
+ resolver = task->resolver;
+ session = task->s;
+ cfg = task->cfg;
+ }
}
lua_pop (L, 1);
}
else {
t = lua_check_text (L, -1);
- body = rspamd_fstring_append (body, t->start, t->len);
+
+ if (t) {
+ body = rspamd_fstring_append(body, t->start, t->len);
+ }
}
lua_pop (L, 1);
cbd->session = session;
}
- if (rspamd_parse_inet_address (&cbd->addr,
+ if (msg->host && rspamd_parse_inet_address (&cbd->addr,
msg->host->str, msg->host->len, RSPAMD_INET_ADDRESS_PARSE_DEFAULT)) {
/* Host is numeric IP, no need to resolve */
gboolean ret;
static int
lua_kann_new_leaf (lua_State *L)
{
- gint dim = luaL_checkinteger (L, 1), i, *ar;
+ int dim = luaL_checkinteger (L, 1), i, *ar;
kad_node_t *t;
if (dim >= 1 && dim < KAD_MAX_DIM && lua_istable (L, 2)) {
- ar = g_malloc0 (sizeof (ar) * dim);
+ ar = g_new0 (int, dim);
for (i = 0; i < dim; i ++) {
lua_rawgeti (L, 2, i + 1);
t = lua_check_text (L, 1);
+ if (!t) {
+ return luaL_error (L, "invalid arguments");
+ }
+
#ifndef HAVE_FMEMOPEN
return luaL_error (L, "no support of loading from memory on your system");
#endif
}
if (n_out <= 0) {
- return luaL_error (L, "invalid outputs count: %d", n_in);
+ return luaL_error (L, "invalid outputs count: %d", n_out);
}
if (n != rspamd_lua_table_size (L, 3) || n == 0) {
rspamd_inet_address_free (ip);
}
msg_err ("bad arguments for redis request");
+ lua_redis_free_args (args, arglens, nargs);
+
lua_pushboolean (L, FALSE);
}
lua_pushnil (L);
}
else {
- sig = g_malloc (sizeof (rspamd_fstring_t));
if (fstat (fd, &st) == -1 ||
(data =
mmap (NULL, st.st_size, PROT_READ, MAP_SHARED, fd, 0))
if (rsa != NULL && data != NULL) {
signature = rspamd_fstring_sized_new (RSA_size (rsa));
+
+ guint siglen = signature->len;
ret = RSA_sign (NID_sha256, data, sz,
- signature->str, (guint *)&signature->len, rsa);
+ signature->str, &siglen, rsa);
if (ret != 1) {
rspamd_fstring_free (signature);
ERR_error_string (ERR_get_error (), NULL));
}
else {
+ signature->len = siglen;
psig = lua_newuserdata (L, sizeof (rspamd_fstring_t *));
rspamd_lua_setclass (L, "rspamd{rsa_signature}", -1);
*psig = signature;
struct rspamd_task *task = lua_check_task (L, 1);
struct tokens_foreach_cbdata cbd;
- cbd.task = task;
- cbd.L = L;
- cbd.idx = 1;
- cbd.normalize = TRUE;
+ if (task) {
+ cbd.task = task;
+ cbd.L = L;
+ cbd.idx = 1;
+ cbd.normalize = TRUE;
- if (lua_type (L, 2) == LUA_TBOOLEAN) {
- cbd.normalize = lua_toboolean (L, 2);
+ if (lua_type(L, 2) == LUA_TBOOLEAN) {
+ cbd.normalize = lua_toboolean(L, 2);
+ }
+ else {
+ cbd.normalize = TRUE;
+ }
+
+ lua_createtable(L,
+ rspamd_symcache_stats_symbols_count(task->cfg->cache), 0);
+ rspamd_symcache_foreach(task->cfg->cache, tokens_foreach_cb, &cbd);
}
else {
- cbd.normalize = TRUE;
+ return luaL_error (L, "invalid arguments");
}
- lua_createtable (L,
- rspamd_symcache_stats_symbols_count (task->cfg->cache), 0);
- rspamd_symcache_foreach (task->cfg->cache, tokens_foreach_cb, &cbd);
-
+ /* Return type is table created */
return 1;
}
gboolean force_new = FALSE, keep = FALSE;
gchar fpath[PATH_MAX];
const gchar *tmpmask = NULL, *fname = NULL;
- guint64 mode = 00600;
+ guint mode = 00600;
gint fd;
struct lua_file_cbdata *cbdata;
GError *err = NULL;
rspamd_snprintf (fpath, sizeof (fpath), "%s", tmpmask);
}
- fd = mkstemp (fpath);
+ fd = g_mkstemp_full (fpath, O_WRONLY|O_CREAT|O_EXCL, mode);
fname = fpath;
if (fd != -1) {
struct iovec *start;
guint niov, i;
gint flags = 0;
+ bool allocated_iov = false;
gsize remain;
gssize r;
struct iovec *cur_iov;
}
else {
cur_iov = g_malloc0 (niov * sizeof (struct iovec));
+ allocated_iov = true;
}
memcpy (cur_iov, wh->iov, niov * sizeof (struct iovec));
r = sendmsg (cbd->fd, &msg, flags);
}
- if (niov >= 1024) {
+ if (allocated_iov) {
g_free (cur_iov);
}
static void
lua_tcp_register_watcher (struct lua_tcp_cbdata *cbd)
{
- if (cbd->item) {
+ if (cbd->item && cbd->task) {
rspamd_symcache_item_async_inc (cbd->task, cbd->item, M);
}
}
}
if (resolver == NULL && cfg == NULL && task == NULL) {
+ g_free (cbd);
return luaL_error (L, "tcp request has bad params: one of "
"{resolver,task,config} should be set");
}
struct rspamd_lua_text *t = lua_check_text (L, 1);
const gchar *p, *end;
gchar *dest, *d;
- gsize byteset[32 / sizeof(gsize)]; /* Bitset for ascii */
+ guint64 byteset[32 / sizeof(guint64)]; /* Bitset for ascii */
gboolean copy = TRUE, seen_8bit = FALSE;
guint *plen;
/* Fill pattern bitset */
memset (byteset, 0, sizeof byteset);
/* All spaces */
- byteset[0] |= GSIZE_FROM_LE (0x100003600);
+ byteset[0] |= GUINT64_FROM_LE (0x100003600LLU);
/* Control characters */
- byteset[0] |= GSIZE_FROM_LE (0xffffffff);
+ byteset[0] |= GUINT64_FROM_LE (0xffffffffLLU);
/* Del character */
- byteset[1] |= GSIZE_FROM_LE (0x8000000000000000);
+ byteset[1] |= GUINT64_FROM_LE (0x8000000000000000LLU);
/* 8 bit characters */
- byteset[2] |= GSIZE_FROM_LE (0xffffffffffffffffLLU);
- byteset[3] |= GSIZE_FROM_LE (0xffffffffffffffffLLU);
+ byteset[2] |= GUINT64_FROM_LE (0xffffffffffffffffLLU);
+ byteset[3] |= GUINT64_FROM_LE (0xffffffffffffffffLLU);
p = t->start;
end = t->start + t->len;