]> source.dussan.org Git - rspamd.git/commitdiff
[Fix] Use message pointer to avoid obsolete data to be cached
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Fri, 13 Nov 2020 18:28:57 +0000 (18:28 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Fri, 13 Nov 2020 18:28:57 +0000 (18:28 +0000)
src/lua/lua_common.h
src/lua/lua_task.c

index 87caa6206e1ab7827a77aa68bd29f3d498d031fe..4c416fa0b5ce683756bcd674ecbd8450b5b4bf74 100644 (file)
@@ -152,7 +152,7 @@ struct rspamd_lua_map {
 
 struct rspamd_lua_cached_entry {
        gint ref;
-       guchar id[4];
+       guint id;
 };
 
 /* Common utility functions */
index 2bf833681ccb2ba8ea71a2d12e0ec871d7a3bb45..188a19671168e56379edd6a6c7a9ad77d9d4b11c 100644 (file)
@@ -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 {