summaryrefslogtreecommitdiffstats
path: root/src/lua
diff options
context:
space:
mode:
Diffstat (limited to 'src/lua')
-rw-r--r--src/lua/lua_buffer.c2
-rw-r--r--src/lua/lua_rsa.c53
-rw-r--r--src/lua/lua_task.c6
-rw-r--r--src/lua/lua_trie.c2
-rw-r--r--src/lua/lua_util.c8
5 files changed, 26 insertions, 45 deletions
diff --git a/src/lua/lua_buffer.c b/src/lua/lua_buffer.c
index 7a23a9579..eedd7f05b 100644
--- a/src/lua/lua_buffer.c
+++ b/src/lua/lua_buffer.c
@@ -91,7 +91,7 @@ lua_io_read_cb (rspamd_fstring_t * in, void *arg)
lua_newuserdata (cbdata->L, sizeof (struct rspamd_io_dispatcher_s *));
rspamd_lua_setclass (cbdata->L, "rspamd{io_dispatcher}", -1);
*pdispatcher = cbdata->d;
- lua_pushlstring (cbdata->L, in->begin, in->len);
+ lua_pushlstring (cbdata->L, in->str, in->len);
if (lua_pcall (cbdata->L, 2, 1, 0) != 0) {
msg_info ("call to session finalizer failed: %s",
diff --git a/src/lua/lua_rsa.c b/src/lua/lua_rsa.c
index 394332fd0..a85d0db71 100644
--- a/src/lua/lua_rsa.c
+++ b/src/lua/lua_rsa.c
@@ -298,16 +298,13 @@ lua_rsa_signature_load (lua_State *L)
sig = g_malloc (sizeof (rspamd_fstring_t));
if (fstat (fd, &st) == -1 ||
(data =
- mmap (NULL, st.st_size, PROT_READ, MAP_SHARED, fd,
- 0)) == MAP_FAILED) {
+ mmap (NULL, st.st_size, PROT_READ, MAP_SHARED, fd, 0))
+ == MAP_FAILED) {
msg_err ("cannot mmap file %s: %s", filename, strerror (errno));
lua_pushnil (L);
}
else {
- sig->size = st.st_size;
- sig->len = sig->size;
- sig->begin = g_malloc (sig->len);
- memcpy (sig->begin, data, sig->len);
+ sig = rspamd_fstring_new_init (data, st.st_size);
psig = lua_newuserdata (L, sizeof (rspamd_fstring_t *));
rspamd_lua_setclass (L, "rspamd{rsa_signature}", -1);
*psig = sig;
@@ -352,7 +349,7 @@ lua_rsa_signature_save (lua_State *L)
lua_pushboolean (L, FALSE);
}
else {
- while (write (fd, sig->begin, sig->len) == -1) {
+ while (write (fd, sig->str, sig->len) == -1) {
if (errno == EINTR) {
continue;
}
@@ -378,14 +375,11 @@ lua_rsa_signature_create (lua_State *L)
{
rspamd_fstring_t *sig, **psig;
const gchar *data;
+ gsize dlen;
- data = luaL_checkstring (L, 1);
+ data = luaL_checklstring (L, 1, &dlen);
if (data != NULL) {
- sig = g_malloc (sizeof (rspamd_fstring_t));
- sig->len = strlen (data);
- sig->size = sig->len;
- sig->begin = g_malloc (sig->len);
- memcpy (sig->begin, data, sig->len);
+ sig = rspamd_fstring_new_init (data, dlen);
psig = lua_newuserdata (L, sizeof (rspamd_fstring_t *));
rspamd_lua_setclass (L, "rspamd{rsa_signature}", -1);
*psig = sig;
@@ -399,12 +393,7 @@ lua_rsa_signature_gc (lua_State *L)
{
rspamd_fstring_t *sig = lua_check_rsa_sign (L, 1);
- if (sig != NULL) {
- if (sig->begin != NULL) {
- g_free (sig->begin);
- }
- g_free (sig);
- }
+ rspamd_fstring_free (sig);
return 0;
}
@@ -435,7 +424,7 @@ lua_rsa_verify_memory (lua_State *L)
if (rsa != NULL && signature != NULL && data != NULL) {
data_sig = g_compute_checksum_for_string (G_CHECKSUM_SHA256, data, -1);
ret = RSA_verify (NID_sha1, data_sig, strlen (data_sig),
- signature->begin, signature->len, rsa);
+ signature->str, signature->len, rsa);
if (ret == 0) {
msg_info ("cannot check rsa signature for data: %s",
ERR_error_string (ERR_get_error (), NULL));
@@ -496,7 +485,7 @@ lua_rsa_verify_file (lua_State *L)
data,
st.st_size);
ret = RSA_verify (NID_sha1, data_sig, strlen (data_sig),
- signature->begin, signature->len, rsa);
+ signature->str, signature->len, rsa);
if (ret == 0) {
msg_info ("cannot check rsa signature for file: %s, %s",
filename, ERR_error_string (ERR_get_error (), NULL));
@@ -534,26 +523,22 @@ lua_rsa_sign_memory (lua_State *L)
RSA *rsa;
rspamd_fstring_t *signature, **psig;
const gchar *data;
- gchar *data_sig;
+ guchar *data_sig;
gint ret;
rsa = lua_check_rsa_privkey (L, 1);
data = luaL_checkstring (L, 2);
if (rsa != NULL && data != NULL) {
- signature = g_malloc (sizeof (rspamd_fstring_t));
- signature->len = RSA_size (rsa);
- signature->size = signature->len;
- signature->begin = g_malloc (signature->len);
+ signature = rspamd_fstring_sized_new (RSA_size (rsa));
data_sig = g_compute_checksum_for_string (G_CHECKSUM_SHA256, data, -1);
ret = RSA_sign (NID_sha1, data_sig, strlen (data_sig),
- signature->begin, (guint *)&signature->len, rsa);
+ signature->str, (guint *)&signature->len, rsa);
if (ret == 0) {
msg_info ("cannot make a signature for data: %s",
ERR_error_string (ERR_get_error (), NULL));
lua_pushnil (L);
- g_free (signature->begin);
- g_free (signature);
+ rspamd_fstring_free (signature);
}
else {
psig = lua_newuserdata (L, sizeof (rspamd_fstring_t *));
@@ -607,21 +592,17 @@ lua_rsa_sign_file (lua_State *L)
lua_pushnil (L);
}
else {
- signature = g_malloc (sizeof (rspamd_fstring_t));
- signature->len = RSA_size (rsa);
- signature->size = signature->len;
- signature->begin = g_malloc (signature->len);
+ signature = rspamd_fstring_sized_new (RSA_size (rsa));
data_sig = g_compute_checksum_for_string (G_CHECKSUM_SHA256,
data,
st.st_size);
ret = RSA_sign (NID_sha1, data_sig, strlen (data_sig),
- signature->begin, (guint *)&signature->len, rsa);
+ signature->str, (guint *)&signature->len, rsa);
if (ret == 0) {
msg_info ("cannot make a signature for data: %s",
ERR_error_string (ERR_get_error (), NULL));
lua_pushnil (L);
- g_free (signature->begin);
- g_free (signature);
+ rspamd_fstring_free (signature);
}
else {
psig = lua_newuserdata (L, sizeof (rspamd_fstring_t *));
diff --git a/src/lua/lua_task.c b/src/lua/lua_task.c
index d52eeb166..4ef772a5c 100644
--- a/src/lua/lua_task.c
+++ b/src/lua/lua_task.c
@@ -638,8 +638,8 @@ lua_task_create_from_buffer (lua_State *L)
ptask = lua_newuserdata (L, sizeof (gpointer));
rspamd_lua_setclass (L, "rspamd{task}", -1);
*ptask = task;
- task->msg.start = rspamd_mempool_alloc (task->task_pool, len + 1);
- memcpy ((gpointer)task->msg.start, data, len);
+ task->msg.begin = rspamd_mempool_alloc (task->task_pool, len);
+ memcpy ((gpointer)task->msg.begin, data, len);
task->msg.len = len;
}
return 1;
@@ -883,7 +883,7 @@ lua_task_get_content (lua_State * L)
t = lua_newuserdata (L, sizeof (*t));
rspamd_lua_setclass (L, "rspamd{text}", -1);
t->len = task->msg.len;
- t->start = task->msg.start;
+ t->start = task->msg.begin;
t->own = FALSE;
return 1;
diff --git a/src/lua/lua_trie.c b/src/lua/lua_trie.c
index bceda4502..b0b1551e3 100644
--- a/src/lua/lua_trie.c
+++ b/src/lua/lua_trie.c
@@ -303,7 +303,7 @@ lua_trie_search_rawmsg (lua_State *L)
gboolean found = FALSE;
if (trie) {
- text = task->msg.start;
+ text = task->msg.begin;
len = task->msg.len;
if (lua_trie_search_str (L, trie, text, len, &state) != 0) {
diff --git a/src/lua/lua_util.c b/src/lua/lua_util.c
index f9f71c532..3a7d00211 100644
--- a/src/lua/lua_util.c
+++ b/src/lua/lua_util.c
@@ -244,8 +244,8 @@ lua_util_process_message (lua_State *L)
task = rspamd_task_new (NULL);
task->cfg = cfg;
task->ev_base = base;
- task->msg.start = rspamd_mempool_alloc (task->task_pool, mlen + 1);
- rspamd_strlcpy ((gpointer)task->msg.start, message, mlen + 1);
+ task->msg.begin = rspamd_mempool_alloc (task->task_pool, mlen);
+ rspamd_strlcpy ((gpointer)task->msg.begin, message, mlen);
task->msg.len = mlen;
task->fin_callback = lua_util_task_fin;
task->fin_arg = &res;
@@ -397,7 +397,7 @@ lua_util_tokenize_text (lua_State *L)
struct rspamd_lua_text *t;
struct process_exception *ex;
GArray *res;
- rspamd_fstring_t *w;
+ rspamd_ftok_t *w;
gboolean compat = FALSE, check_sig = FALSE;
if (lua_type (L, 1) == LUA_TSTRING) {
@@ -465,7 +465,7 @@ lua_util_tokenize_text (lua_State *L)
lua_newtable (L);
for (i = 0; i < res->len; i ++) {
- w = &g_array_index (res, rspamd_fstring_t, i);
+ w = &g_array_index (res, rspamd_ftok_t, i);
lua_pushlstring (L, w->begin, w->len);
lua_rawseti (L, -2, i + 1);
}