else
type = EVENT_FILTER_NODE_TYPE_EVENT_FIELD;
+ /* only fields support comparators other than EQ */
+ if ((type != EVENT_FILTER_NODE_TYPE_EVENT_FIELD) &&
+ (op != EVENT_FILTER_OP_CMP_EQ)) {
+ state->error = "Only fields support inequality comparisons";
+ return NULL;
+ }
+
node = p_new(state->pool, struct event_filter_node, 1);
node->type = type;
node->op = op;
| key_value { $$ = $1; }
;
-key_value : key op value { $$ = key_value(state, $1, $3, $2); }
+key_value : key op value {
+ $$ = key_value(state, $1, $3, $2);
+ if ($$ == NULL) {
+ yyerror(state, state->error);
+ YYERROR;
+ }
+ }
;
key : TOKEN { $$ = $1; }
* Test '<key><op><value>' with each possible operator and each possible
* quoting of <key> and <value>. Some quotings are not allowed. The keyq
* and valueq arguments specify whether the <key> and <value> strings
- * should be quoted.
+ * should be quoted. key_special indicates that the key is *not* a field
+ * and therefore only the = operator should parse successfully.
*/
static void generated_single_comparison(const char *name,
bool parens,
const char *key,
enum quoting keyq,
+ bool key_special,
const char *value_in,
const char *value_exp,
enum quoting valueq)
{
unsigned int c, q;
+ bool should_fail;
for (c = 0; c < N_ELEMENTS(comparators); c++) {
string_t *output = t_str_new(128);
- str_append_c(output, '(');
- if (keyq != QUOTE_MUST_NOT)
+ if (key_special && (strcmp(comparators[c], "=") != 0)) {
+ /* the key is a not a field, only = is allowed */
+ str_append(output, "event filter: Only fields support inequality comparisons");
+ should_fail = TRUE;
+ } else {
+ /* the key is a field, all comparators are allowed */
+ str_append_c(output, '(');
+ if (keyq != QUOTE_MUST_NOT)
+ str_append_c(output, '"');
+ str_append(output, key);
+ if (keyq != QUOTE_MUST_NOT)
+ str_append_c(output, '"');
+ str_append(output, comparators[c]);
str_append_c(output, '"');
- str_append(output, key);
- if (keyq != QUOTE_MUST_NOT)
+ str_append_escaped(output, value_exp, strlen(value_exp));
str_append_c(output, '"');
- str_append(output, comparators[c]);
- str_append_c(output, '"');
- str_append_escaped(output, value_exp, strlen(value_exp));
- str_append_c(output, '"');
- str_append_c(output, ')');
+ str_append_c(output, ')');
+ should_fail = FALSE;
+ }
for (q = 0; q < 4; q++) {
const bool qkey = (q & 1) == 1;
testcase(name,
str_c(input),
str_c(output),
- FALSE);
+ should_fail);
}
}
}
parens,
what_special[w],
QUOTE_MUST_NOT,
+ TRUE,
values_single[v],
values_single[v],
QUOTE_MAY);
parens,
what_special[w],
QUOTE_MUST_NOT,
+ TRUE,
values_multi[v],
values_multi[v],
QUOTE_MUST);
parens,
what_special[w],
QUOTE_MUST_NOT,
+ TRUE,
values_oper[v].in,
values_oper[v].out_unquoted,
QUOTE_MUST_NOT);
parens,
what_special[w],
QUOTE_MUST_NOT,
+ TRUE,
values_oper[v].in,
values_oper[v].out_quoted,
QUOTE_MUST);
parens,
what_fields_single[w],
QUOTE_MAY,
+ FALSE,
values_single[v],
values_single[v],
QUOTE_MAY);
parens,
what_fields_single[w],
QUOTE_MAY,
+ FALSE,
values_multi[v],
values_multi[v],
QUOTE_MUST);
parens,
what_fields_single[w],
QUOTE_MAY,
+ FALSE,
values_oper[v].in,
values_oper[v].out_unquoted,
QUOTE_MUST_NOT);
parens,
what_fields_single[w],
QUOTE_MAY,
+ FALSE,
values_oper[v].in,
values_oper[v].out_quoted,
QUOTE_MUST);