From 3edf9af2293b2121f7346d29cbea49223c6cfc5f Mon Sep 17 00:00:00 2001 From: Karl Fleischmann Date: Wed, 21 Dec 2022 15:03:30 +0100 Subject: [PATCH] lib: Add string inequality warning to strlist fields in event filters --- src/lib/event-filter.c | 15 ++++++++++++++- src/lib/test-event-filter.c | 8 ++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/lib/event-filter.c b/src/lib/event-filter.c index c619828ac6..a36e4e43ee 100644 --- a/src/lib/event-filter.c +++ b/src/lib/event-filter.c @@ -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(); diff --git a/src/lib/test-event-filter.c b/src/lib/test-event-filter.c index 4f37a1c17e..3b317bcae3 100644 --- a/src/lib/test-event-filter.c +++ b/src/lib/test-event-filter.c @@ -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(); } -- 2.47.3