Fix CID 1491157: use after free.
[claws.git] / src / filtering.c
index e4f3d0105bafa5b1a093042d5d1a345a58810fb8..9e1d98158dafb70c1cf38ad4ead978a5ca8beb60 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * Claws Mail -- a GTK+ based, lightweight, and fast e-mail client
- * Copyright (C) 1999-2015 Hiroyuki Yamamoto & The Claws Mail Team
+ * Copyright (C) 1999-2020 the Claws Mail Team and Hiroyuki Yamamoto
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -473,8 +473,8 @@ static gboolean filteringaction_apply(FilteringAction * action, MsgInfo * info)
                        AddressBookFile *abf = NULL;
                        ItemFolder *folder = NULL;
 #endif
-                       gchar *buf;
-                       Header *header;
+                       gchar *buf = NULL;
+                       Header *header = NULL;
                        gint errors = 0;
 
 #ifndef USE_ALT_ADDRBOOK
@@ -510,15 +510,15 @@ static gboolean filteringaction_apply(FilteringAction * action, MsgInfo * info)
                                        path = action->destination;
                                start_address_completion(path);
 
-                               address_list = address_list_append(address_list, header->body);
+                               address_list = g_slist_append(address_list, header->body);
                                for (walk = address_list; walk != NULL; walk = walk->next) {
                                        gchar *stripped_addr = g_strdup(walk->data);
                                        extract_address(stripped_addr);
 
                                        if (complete_matches_found(walk->data) == 0) {
                                                gchar *name = procheader_get_fromname(walk->data);
-                                               debug_print("adding address '%s' to addressbook '%s'\n",
-                                                               stripped_addr, action->destination);
+                                               debug_print("adding '%s <%s>' to addressbook '%s'\n",
+                                                               name, stripped_addr, action->destination);
 #ifndef USE_ALT_ADDRBOOK
                                                if (!addrbook_add_contact(abf, folder, name, stripped_addr, NULL)) {
 #else
@@ -784,13 +784,23 @@ static gboolean filtering_is_final_action(FilteringAction *filtering_action)
        case MATCHACTION_MOVE:
        case MATCHACTION_DELETE:
        case MATCHACTION_STOP:
-       case MATCHACTION_MARK_AS_SPAM:
                return TRUE; /* MsgInfo invalid for message */
        default:
                return FALSE;
        }
 }
 
+gboolean processing_enabled(GSList *filtering_list)
+{
+       GSList  *l;
+       for (l = filtering_list; l != NULL; l = g_slist_next(l)) {
+               FilteringProp * filtering = (FilteringProp *) l->data;
+               if (filtering->enabled)
+                       return TRUE;
+       }
+       return FALSE;
+}
+
 static gboolean filter_msginfo(GSList * filtering_list, MsgInfo * info, PrefsAccount* ac_prefs)
 {
        GSList  *l;
@@ -872,7 +882,7 @@ gboolean filter_message_by_msginfo(GSList *flist, MsgInfo *info, PrefsAccount* a
 
        if (prefs_common.enable_filtering_debug) {
                gchar *tmp = _("undetermined");
-#ifndef G_OS_WIN32
+
                switch (context) {
                case FILTERING_INCORPORATION:
                        tmp = _("incorporation");
@@ -898,9 +908,7 @@ gboolean filter_message_by_msginfo(GSList *flist, MsgInfo *info, PrefsAccount* a
                        debug_filtering_session = FALSE;
                        break;
                }
-#else
-               debug_filtering_session = FALSE;
-#endif
+
                if (debug_filtering_session) {
                        gchar *file = procmsg_get_message_file_path(info);
                        gchar *spc = g_strnfill(LOG_TIME_LEN + 1, ' ');
@@ -1069,8 +1077,8 @@ static void prefs_filtering_free(GSList * prefs_filtering)
        while (prefs_filtering != NULL) {
                FilteringProp * filtering = (FilteringProp *)
                        prefs_filtering->data;
-               filteringprop_free(filtering);
                prefs_filtering = g_slist_remove(prefs_filtering, filtering);
+               filteringprop_free(filtering);
        }
 }