From: Karl Fleischmann Date: Mon, 19 Dec 2022 14:18:40 +0000 (+0100) Subject: lib: Warn about unsupported inequality string comparisons in event filters X-Git-Tag: 2.4.0~3239 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ea83fac1bcfedbb7a8f100dac62d322c8451f974;p=thirdparty%2Fdovecot%2Fcore.git lib: Warn about unsupported inequality string comparisons in event filters --- diff --git a/src/lib/event-filter-private.h b/src/lib/event-filter-private.h index 2c80b1d14d..bb9b0f638a 100644 --- a/src/lib/event-filter-private.h +++ b/src/lib/event-filter-private.h @@ -87,6 +87,7 @@ struct event_filter_node { bool ambiguous_unit:1; bool warned_ambiguous_unit:1; + bool warned_string_inequality:1; bool warned_type_mismatch:1; }; diff --git a/src/lib/event-filter.c b/src/lib/event-filter.c index 335312f829..3bb52d6d2b 100644 --- a/src/lib/event-filter.c +++ b/src/lib/event-filter.c @@ -254,6 +254,7 @@ clone_expr(pool_t pool, struct event_filter_node *old) new->ambiguous_unit = old->ambiguous_unit; new->warned_ambiguous_unit = old->warned_ambiguous_unit; new->warned_type_mismatch = old->warned_type_mismatch; + new->warned_string_inequality = old->warned_string_inequality; return new; } @@ -590,8 +591,21 @@ event_match_field(struct event *event, struct event_filter_node *node, switch (field->value_type) { case EVENT_FIELD_VALUE_TYPE_STR: + /* We only support string equality comparisons. */ if (node->op != EVENT_FILTER_OP_CMP_EQ) { - /* we only support string equality comparisons */ + /* Warn about non-equality comparisons. */ + if (!node->warned_string_inequality) { + const char *name = event->sending_name; + /* Use i_warning to prevent event filter recursions. */ + i_warning("Event filter for string 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; } if (field->value.str[0] == '\0') {