commit c7101e6: [Fix] Use message pointer to avoid obsolete data to be cached

Vsevolod Stakhov vsevolod at highsecure.ru
Fri Nov 13 18:35:07 UTC 2020


Author: Vsevolod Stakhov
Date: 2020-11-13 18:28:57 +0000
URL: https://github.com/rspamd/rspamd/commit/c7101e602f931f43b8f79a82f4616ba3b7ef3de9 (HEAD -> master)

[Fix] Use message pointer to avoid obsolete data to be cached

---
 src/lua/lua_common.h |  2 +-
 src/lua/lua_task.c   | 23 +++++++++--------------
 2 files changed, 10 insertions(+), 15 deletions(-)

diff --git a/src/lua/lua_common.h b/src/lua/lua_common.h
index 87caa6206..4c416fa0b 100644
--- a/src/lua/lua_common.h
+++ b/src/lua/lua_common.h
@@ -152,7 +152,7 @@ struct rspamd_lua_map {
 
 struct rspamd_lua_cached_entry {
 	gint ref;
-	guchar id[4];
+	guint id;
 };
 
 /* Common utility functions */
diff --git a/src/lua/lua_task.c b/src/lua/lua_task.c
index 2bf833681..188a19671 100644
--- a/src/lua/lua_task.c
+++ b/src/lua/lua_task.c
@@ -1385,7 +1385,7 @@ lua_task_set_cached (lua_State *L, struct rspamd_task *task, const gchar *key,
 	entry->ref = luaL_ref (L, LUA_REGISTRYINDEX);
 
 	if (task->message) {
-		memcpy (entry->id, MESSAGE_FIELD (task, digest), sizeof (entry->id));
+		entry->id = GPOINTER_TO_UINT (task->message);
 	}
 }
 
@@ -1399,8 +1399,7 @@ lua_task_get_cached (lua_State *L, struct rspamd_task *task, const gchar *key)
 	entry = g_hash_table_lookup (task->lua_cache, key);
 
 	if (entry != NULL && (task->message &&
-						  memcmp (entry->id, MESSAGE_FIELD (task, digest),
-								  sizeof (entry->id)) == 0)) {
+						  entry->id == GPOINTER_TO_UINT (task->message))) {
 		lua_rawgeti (L, LUA_REGISTRYINDEX, entry->ref);
 
 		return TRUE;
@@ -2642,18 +2641,14 @@ lua_task_get_parts (lua_State * L)
 
 	if (task != NULL) {
 		if (task->message) {
-			if (!lua_task_get_cached (L, task, "mime_parts")) {
-				lua_createtable (L, MESSAGE_FIELD (task, parts)->len, 0);
-
-				PTR_ARRAY_FOREACH (MESSAGE_FIELD (task, parts), i, part) {
-					ppart = lua_newuserdata (L, sizeof (struct rspamd_mime_part *));
-					*ppart = part;
-					rspamd_lua_setclass (L, "rspamd{mimepart}", -1);
-					/* Make it array */
-					lua_rawseti (L, -2, i + 1);
-				}
+			lua_createtable (L, MESSAGE_FIELD (task, parts)->len, 0);
 
-				lua_task_set_cached (L, task, "mime_parts", -1);
+			PTR_ARRAY_FOREACH (MESSAGE_FIELD (task, parts), i, part) {
+				ppart = lua_newuserdata (L, sizeof (struct rspamd_mime_part *));
+				*ppart = part;
+				rspamd_lua_setclass (L, "rspamd{mimepart}", -1);
+				/* Make it array */
+				lua_rawseti (L, -2, i + 1);
 			}
 		}
 		else {


More information about the Commits mailing list