]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib: Add string inequality warning to strlist fields in event filters
authorKarl Fleischmann <karl.fleischmann@open-xchange.com>
Wed, 21 Dec 2022 14:03:30 +0000 (15:03 +0100)
committeraki.tuomi <aki.tuomi@open-xchange.com>
Mon, 9 Jan 2023 09:48:38 +0000 (09:48 +0000)
src/lib/event-filter.c
src/lib/test-event-filter.c

index c619828ac6d6f3f279240ba4aa3675917d3b5d87..a36e4e43eea6295fd4ccd738ef1271b51903c7e0 100644 (file)
@@ -683,8 +683,21 @@ event_match_field(struct event *event, struct event_filter_node *node,
        case EVENT_FIELD_VALUE_TYPE_STRLIST:
                /* check if the value is (or is not) on the list,
                   only string matching makes sense here. */
-               if (node->op != EVENT_FILTER_OP_CMP_EQ)
+               if (node->op != EVENT_FILTER_OP_CMP_EQ) {
+                       if (!node->warned_string_inequality) {
+                               const char *name = event->sending_name;
+                               i_warning("Event filter for string list field "
+                                         "'%s' only supports equality "
+                                         "operation '=' not '%s'. (event=%s, "
+                                         "source=%s:%u)",
+                                         wanted_field->key,
+                                         event_filter_export_query_expr_op(node->op),
+                                         name != NULL ? name : "",
+                                         source_filename, source_linenum);
+                               node->warned_string_inequality = TRUE;
+                       }
                        return FALSE;
+               }
                return event_match_strlist(event, wanted_field, use_strcmp);
        }
        i_unreached();
index 4f37a1c17e3a4abcf2461b93107f58898fab7bae..3b317bcae388a5cdf08f539369ea34f0df54f71b 100644 (file)
@@ -327,6 +327,14 @@ static void test_event_filter_strlist(void)
        test_assert(event_filter_match(filter, e, &failure_ctx));
        event_filter_unref(&filter);
 
+       filter = event_filter_create();
+       event_filter_parse("abc>one", filter, NULL);
+       test_expect_error_string("Event filter for string field 'abc' only "
+                                "supports equality operation '=' not '>'.");
+       test_assert(!event_filter_match(filter, e, &failure_ctx));
+       test_expect_no_more_errors();
+       event_filter_unref(&filter);
+
        event_unref(&e);
        test_end();
 }