]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib: Try to interpret filter values as sizes when parsing integer event values
authorKarl Fleischmann <karl.fleischmann@open-xchange.com>
Thu, 10 Nov 2022 12:28:54 +0000 (13:28 +0100)
committeraki.tuomi <aki.tuomi@open-xchange.com>
Mon, 21 Nov 2022 17:50:26 +0000 (17:50 +0000)
This allows event filter values to be given as "16M" or "1G".

src/lib/event-filter-parser.y

index 12b7d4bbc5255e798f1220f6311d14d3c06710bf..dbf936b3c48089713b8ab5c546179e52899809fe 100644 (file)
@@ -10,6 +10,7 @@
 
 %{
 #include "lib.h"
+#include "str-parse.h"
 #include "wildcard-match.h"
 #include "lib-event-private.h"
 #include "event-filter-private.h"
@@ -97,13 +98,23 @@ static struct event_filter_node *key_value(struct event_filter_parser_state *sta
 
                /* Filter currently supports only comparing strings
                   and numbers. */
-               if (str_to_intmax(b, &node->field.value.intmax) < 0) {
-                       /* not a number - no problem
-                          Either we have a string, or a number with wildcards */
-                       node->field.value.intmax = INT_MIN;
-               } else {
-                       /* leave a hint that this is in fact a valid number */
+               if (str_to_intmax(b, &node->field.value.intmax) == 0) {
+                       /* Leave a hint that this is in fact a valid number. */
                        node->field.value_type = EVENT_FIELD_VALUE_TYPE_INTMAX;
+               } else {
+                       /* This field contains no valid number.
+                          Either this is a string that contains a size unit, a
+                          number with wildcard or another arbitrary string. */
+                       node->field.value.intmax = INT_MIN;
+
+                       /* If the field contains a size unit, take that. */
+                       uoff_t bytes;
+                       const char *error;
+                       int ret = str_parse_get_size(b, &bytes, &error);
+                       if (ret == 0 && bytes <= INTMAX_MAX) {
+                               node->field.value.intmax = (intmax_t) bytes;
+                               node->field.value_type = EVENT_FIELD_VALUE_TYPE_INTMAX;
+                       }
                }
 
                if (wildcard_is_literal(node->field.value.str))