aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@rspamd.com>2024-11-06 18:56:18 +0600
committerGitHub <noreply@github.com>2024-11-06 18:56:18 +0600
commitc763d4bb58423d1e356263d989a81c7546e577c5 (patch)
treeb943da3d6b7097b2b897c7236c1009ae46185702 /src
parentebf6f29f301c06b9090fe11cb3865b2759f204e3 (diff)
parentb5ba154e32a7c72a2be852b50a92a7c681f5da04 (diff)
downloadrspamd-c763d4bb58423d1e356263d989a81c7546e577c5.tar.gz
rspamd-c763d4bb58423d1e356263d989a81c7546e577c5.zip
Merge branch 'master' into master
Diffstat (limited to 'src')
-rw-r--r--src/lua/lua_common.h5
-rw-r--r--src/lua/lua_compress.c12
-rw-r--r--src/lua/lua_text.c4
-rw-r--r--src/lua/lua_util.c11
-rw-r--r--src/plugins/lua/mime_types.lua1
-rw-r--r--src/ragel/smtp_addr_parser.rl18
6 files changed, 30 insertions, 21 deletions
diff --git a/src/lua/lua_common.h b/src/lua/lua_common.h
index 198735c66..1d39d0c52 100644
--- a/src/lua/lua_common.h
+++ b/src/lua/lua_common.h
@@ -94,8 +94,7 @@ static inline int lua_absindex(lua_State *L, int i)
#define LUA_PUBLIC_FUNCTION_DEF(class, name) int lua_##class##_##name(lua_State *L)
#define LUA_INTERFACE_DEF(class, name) \
{ \
- #name, lua_##class##_##name \
- }
+ #name, lua_##class##_##name}
extern const luaL_reg null_reg[];
@@ -281,7 +280,7 @@ struct rspamd_lua_text *lua_check_text_or_string(lua_State *L, int pos);
* @return
*/
struct rspamd_lua_text *lua_new_text(lua_State *L, const char *start,
- gsize len, gboolean own);
+ gsize len, gboolean allocate_memory);
/**
* Create new text object from task pool if allocation is needed
* @param task
diff --git a/src/lua/lua_compress.c b/src/lua/lua_compress.c
index 4a348404c..c82394ed6 100644
--- a/src/lua/lua_compress.c
+++ b/src/lua/lua_compress.c
@@ -1,11 +1,11 @@
-/*-
- * Copyright 2021 Vsevolod Stakhov
+/*
+ * Copyright 2024 Vsevolod Stakhov
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -504,7 +504,8 @@ lua_zstd_compress_stream(lua_State *L)
return lua_zstd_push_error(L, err);
}
- lua_new_text(L, onb.dst, onb.pos, TRUE);
+ t = lua_new_text(L, onb.dst, onb.pos, FALSE);
+ t->flags |= RSPAMD_TEXT_FLAG_OWN;
return 1;
}
@@ -598,7 +599,8 @@ lua_zstd_decompress_stream(lua_State *L)
return lua_zstd_push_error(L, err);
}
- lua_new_text(L, onb.dst, onb.pos, TRUE);
+ t = lua_new_text(L, onb.dst, onb.pos, FALSE);
+ t->flags |= RSPAMD_TEXT_FLAG_OWN;
return 1;
}
diff --git a/src/lua/lua_text.c b/src/lua/lua_text.c
index 4478314f1..3342fc95c 100644
--- a/src/lua/lua_text.c
+++ b/src/lua/lua_text.c
@@ -312,14 +312,14 @@ lua_check_text_or_string(lua_State *L, int pos)
}
struct rspamd_lua_text *
-lua_new_text(lua_State *L, const char *start, gsize len, gboolean own)
+lua_new_text(lua_State *L, const char *start, gsize len, gboolean allocate_memory)
{
struct rspamd_lua_text *t;
t = lua_newuserdata(L, sizeof(*t));
t->flags = 0;
- if (own) {
+ if (allocate_memory) {
char *storage;
if (len > 0) {
diff --git a/src/lua/lua_util.c b/src/lua/lua_util.c
index 92f831f6f..251d1e1e7 100644
--- a/src/lua/lua_util.c
+++ b/src/lua/lua_util.c
@@ -1025,7 +1025,12 @@ lua_util_encode_base64(lua_State *L)
}
if (out != NULL) {
- lua_new_text(L, out, outlen, TRUE);
+ /*
+ * Manually set OWN flag, as `lua_new_text` will allocate another chunk of memory,
+ * and we will have memory leak of the memory allocated by `rspamd_encode_base64_fold`
+ */
+ t = lua_new_text(L, out, outlen, FALSE);
+ t->flags = RSPAMD_TEXT_FLAG_OWN;
}
else {
lua_pushnil(L);
@@ -1650,7 +1655,9 @@ lua_util_transliterate(lua_State *L)
gsize outlen;
char *transliterated = rspamd_utf8_transliterate(t->start, t->len, &outlen);
- lua_new_text(L, transliterated, outlen, TRUE);
+
+ t = lua_new_text(L, transliterated, outlen, FALSE);
+ t->flags = RSPAMD_TEXT_FLAG_OWN;
return 1;
}
diff --git a/src/plugins/lua/mime_types.lua b/src/plugins/lua/mime_types.lua
index ec8e566f2..c69fa1e7b 100644
--- a/src/plugins/lua/mime_types.lua
+++ b/src/plugins/lua/mime_types.lua
@@ -75,6 +75,7 @@ local settings = {
mht = 2,
mhtml = 2,
oqy = 2,
+ rdp = 2,
rqy = 2,
sfx = 2,
slk = 2,
diff --git a/src/ragel/smtp_addr_parser.rl b/src/ragel/smtp_addr_parser.rl
index b5b4863d3..330f3f01d 100644
--- a/src/ragel/smtp_addr_parser.rl
+++ b/src/ragel/smtp_addr_parser.rl
@@ -8,33 +8,33 @@
action IP4_end {}
action User_start {
- addr->user = p;
+ addr->user = (const char *)p;
}
action User_end {
if (addr->user) {
- addr->user_len = p - addr->user;
+ addr->user_len = (const char *)p - addr->user;
}
}
action Domain_start {
- addr->domain = p;
+ addr->domain = (const char *)p;
}
action Domain_end {
if (addr->domain) {
- addr->domain_len = p - addr->domain;
+ addr->domain_len = (const char *)p - addr->domain;
}
}
action Domain_addr_start {
- addr->domain = p;
+ addr->domain = (const char *)p;
addr->flags |= RSPAMD_EMAIL_ADDR_IP;
}
action Domain_addr_end {
if (addr->domain) {
- addr->domain_len = p - addr->domain;
+ addr->domain_len = (const char *)p - addr->domain;
}
}
@@ -64,12 +64,12 @@
}
action Addr_start {
- addr->addr = p;
+ addr->addr = (const char *)p;
}
action Addr_end {
if (addr->addr) {
- addr->addr_len = p - addr->addr;
+ addr->addr_len = (const char *)p - addr->addr;
}
}
@@ -87,7 +87,7 @@
int
rspamd_smtp_addr_parse (const char *data, size_t len, struct rspamd_email_address *addr)
{
- const char *p = data, *pe = data + len, *eof;
+ const unsigned char *p = (const unsigned char *)data, *pe = (const unsigned char *)data + len, *eof;
int cs;
g_assert (addr != NULL);