commit 69c4a64: [Minor] Lua_text: Add a hack to use several distinct fake texts
Vsevolod Stakhov
vsevolod at highsecure.ru
Fri Apr 2 14:42:05 UTC 2021
Author: Vsevolod Stakhov
Date: 2021-04-02 15:37:31 +0100
URL: https://github.com/rspamd/rspamd/commit/69c4a64a428965c4d08ac8706d9c28c5473a8f8c
[Minor] Lua_text: Add a hack to use several distinct fake texts
---
src/lua/lua_text.c | 19 +++++++++++++------
1 file changed, 13 insertions(+), 6 deletions(-)
diff --git a/src/lua/lua_text.c b/src/lua/lua_text.c
index c90c2e6bf..dde7e2c23 100644
--- a/src/lua/lua_text.c
+++ b/src/lua/lua_text.c
@@ -288,19 +288,26 @@ lua_check_text_or_string (lua_State * L, gint pos)
return ud ? (struct rspamd_lua_text *) ud : NULL;
}
else if (pos_type == LUA_TSTRING) {
- /* Fake static lua_text */
- static struct rspamd_lua_text fake_text;
+ /*
+ * Fake static lua_text, we allow to use this function multiple times
+ * by having a small array of static structures.
+ */
+ static int cur_txt_idx = 0;
+ static struct rspamd_lua_text fake_text[4];
gsize len;
+ int sel_idx;
+
+ sel_idx = cur_txt_idx++ % G_N_ELEMENTS (fake_text);
+ fake_text[sel_idx].start = lua_tolstring (L, pos, &len);
- fake_text.start = lua_tolstring (L, pos, &len);
if (len >= G_MAXUINT) {
return NULL;
}
- fake_text.len = len;
- fake_text.flags = RSPAMD_TEXT_FLAG_FAKE;
+ fake_text[sel_idx].len = len;
+ fake_text[sel_idx].flags = RSPAMD_TEXT_FLAG_FAKE;
- return &fake_text;
+ return &fake_text[sel_idx];
}
return NULL;
More information about the Commits
mailing list