Skip to content

EQL: Disallow chained comparisons #62567

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Sep 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions x-pack/plugin/eql/src/main/antlr/EqlBase.g4
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,15 @@ booleanExpression


valueExpression
: primaryExpression predicate? #valueExpressionDefault
| operator=(MINUS | PLUS) valueExpression #arithmeticUnary
| left=valueExpression operator=(ASTERISK | SLASH | PERCENT) right=valueExpression #arithmeticBinary
| left=valueExpression operator=(PLUS | MINUS) right=valueExpression #arithmeticBinary
| left=valueExpression comparisonOperator right=valueExpression #comparison
: operatorExpression #valueExpressionDefault
| left=operatorExpression comparisonOperator right=operatorExpression #comparison
;

operatorExpression
: primaryExpression predicate? #operatorExpressionDefault
| operator=(MINUS | PLUS) operatorExpression #arithmeticUnary
| left=operatorExpression operator=(ASTERISK | SLASH | PERCENT) right=operatorExpression #arithmeticBinary
| left=operatorExpression operator=(PLUS | MINUS) right=operatorExpression #arithmeticBinary
;

// workaround for
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,18 @@ class EqlBaseBaseListener implements EqlBaseListener {
* <p>The default implementation does nothing.</p>
*/
@Override public void exitComparison(EqlBaseParser.ComparisonContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void enterOperatorExpressionDefault(EqlBaseParser.OperatorExpressionDefaultContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void exitOperatorExpressionDefault(EqlBaseParser.OperatorExpressionDefaultContext ctx) { }
/**
* {@inheritDoc}
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,13 @@ class EqlBaseBaseVisitor<T> extends AbstractParseTreeVisitor<T> implements EqlBa
* {@link #visitChildren} on {@code ctx}.</p>
*/
@Override public T visitComparison(EqlBaseParser.ComparisonContext ctx) { return visitChildren(ctx); }
/**
* {@inheritDoc}
*
* <p>The default implementation returns the result of calling
* {@link #visitChildren} on {@code ctx}.</p>
*/
@Override public T visitOperatorExpressionDefault(EqlBaseParser.OperatorExpressionDefaultContext ctx) { return visitChildren(ctx); }
/**
* {@inheritDoc}
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,27 +229,39 @@ interface EqlBaseListener extends ParseTreeListener {
* @param ctx the parse tree
*/
void exitComparison(EqlBaseParser.ComparisonContext ctx);
/**
* Enter a parse tree produced by the {@code operatorExpressionDefault}
* labeled alternative in {@link EqlBaseParser#operatorExpression}.
* @param ctx the parse tree
*/
void enterOperatorExpressionDefault(EqlBaseParser.OperatorExpressionDefaultContext ctx);
/**
* Exit a parse tree produced by the {@code operatorExpressionDefault}
* labeled alternative in {@link EqlBaseParser#operatorExpression}.
* @param ctx the parse tree
*/
void exitOperatorExpressionDefault(EqlBaseParser.OperatorExpressionDefaultContext ctx);
/**
* Enter a parse tree produced by the {@code arithmeticBinary}
* labeled alternative in {@link EqlBaseParser#valueExpression}.
* labeled alternative in {@link EqlBaseParser#operatorExpression}.
* @param ctx the parse tree
*/
void enterArithmeticBinary(EqlBaseParser.ArithmeticBinaryContext ctx);
/**
* Exit a parse tree produced by the {@code arithmeticBinary}
* labeled alternative in {@link EqlBaseParser#valueExpression}.
* labeled alternative in {@link EqlBaseParser#operatorExpression}.
* @param ctx the parse tree
*/
void exitArithmeticBinary(EqlBaseParser.ArithmeticBinaryContext ctx);
/**
* Enter a parse tree produced by the {@code arithmeticUnary}
* labeled alternative in {@link EqlBaseParser#valueExpression}.
* labeled alternative in {@link EqlBaseParser#operatorExpression}.
* @param ctx the parse tree
*/
void enterArithmeticUnary(EqlBaseParser.ArithmeticUnaryContext ctx);
/**
* Exit a parse tree produced by the {@code arithmeticUnary}
* labeled alternative in {@link EqlBaseParser#valueExpression}.
* labeled alternative in {@link EqlBaseParser#operatorExpression}.
* @param ctx the parse tree
*/
void exitArithmeticUnary(EqlBaseParser.ArithmeticUnaryContext ctx);
Expand Down
Loading