From: Karl Fleischmann Date: Wed, 21 Dec 2022 14:03:30 +0000 (+0100) Subject: lib: Add string inequality warning to strlist fields in event filters X-Git-Tag: 2.4.0~3236 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3edf9af2293b2121f7346d29cbea49223c6cfc5f;p=thirdparty%2Fdovecot%2Fcore.git lib: Add string inequality warning to strlist fields in event filters --- 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(); }