]> git.ipfire.org Git - thirdparty/rspamd.git/commitdiff
[Fix] Another safe-guards for learning/classifying an empty message 5118/head
authorVsevolod Stakhov <vsevolod@rspamd.com>
Wed, 28 Aug 2024 12:10:28 +0000 (13:10 +0100)
committerVsevolod Stakhov <vsevolod@rspamd.com>
Wed, 28 Aug 2024 12:10:28 +0000 (13:10 +0100)
src/libstat/stat_process.c

index ad976e7135f3c767f537544bf1312acb57a23313..5db3af6ce785ce49ce83fbeb204106689275a8a9 100644 (file)
@@ -509,6 +509,14 @@ rspamd_stat_classify(struct rspamd_task *task, lua_State *L, unsigned int stage,
                return ret;
        }
 
+       if (task->message == NULL) {
+               ret = RSPAMD_STAT_PROCESS_ERROR;
+               msg_err_task("trying to classify empty message");
+
+               task->processed_stages |= stage;
+               return ret;
+       }
+
        if (stage == RSPAMD_TASK_STAGE_CLASSIFIERS_PRE) {
                /* Preprocess tokens */
                rspamd_stat_preprocess(st_ctx, task, FALSE, FALSE);
@@ -892,6 +900,18 @@ rspamd_stat_learn(struct rspamd_task *task,
                return ret;
        }
 
+
+       if (task->message == NULL) {
+               ret = RSPAMD_STAT_PROCESS_ERROR;
+               if (err && *err == NULL) {
+                       g_set_error(err, rspamd_stat_quark(), 500,
+                                               "Trying to learn an empty message");
+               }
+
+               task->processed_stages |= stage;
+               return ret;
+       }
+
        if (stage == RSPAMD_TASK_STAGE_LEARN_PRE) {
                /* Process classifiers */
                rspamd_stat_preprocess(st_ctx, task, TRUE, spam);