From 14a9968a56f8b35138bab172aa7ce796f5d98e03 Mon Sep 17 00:00:00 2001 From: Phil Sutter Date: Fri, 24 Aug 2018 13:26:57 +0200 Subject: parser_bison: Fix for ECN keyword in LHS of relational Of all possible TCP flags, 'ecn' is special since it is recognized by lex as a keyword (there is a a field in IPv4 and IPv6 headers with the same name). Therefore it is listed in keyword_expr, but that was sufficient for RHS only. The following statement reproduces the issue: | tcp flags & (syn | ecn) == (syn | ecn) The solution is to limit binop expressions to accept an RHS expression on RHS ("real" LHS expressions don't make much sense there anyway), which then allows keyword_expr to occur there. In order to maintain the recursive behaviour if braces are present, allow primary_rhs_expr to consist of a basic_rhs_expr enclosed in braces. This in turn requires for braced RHS part in relational_expr to be dropped, otherwise bison complains about shift/reduce conflict. Signed-off-by: Phil Sutter Signed-off-by: Pablo Neira Ayuso --- src/parser_bison.y | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/parser_bison.y b/src/parser_bison.y index 831090b6..c9189e9c 100644 --- a/src/parser_bison.y +++ b/src/parser_bison.y @@ -3119,32 +3119,32 @@ osf_expr : OSF NAME ; shift_expr : primary_expr - | shift_expr LSHIFT primary_expr + | shift_expr LSHIFT primary_rhs_expr { $$ = binop_expr_alloc(&@$, OP_LSHIFT, $1, $3); } - | shift_expr RSHIFT primary_expr + | shift_expr RSHIFT primary_rhs_expr { $$ = binop_expr_alloc(&@$, OP_RSHIFT, $1, $3); } ; and_expr : shift_expr - | and_expr AMPERSAND shift_expr + | and_expr AMPERSAND shift_rhs_expr { $$ = binop_expr_alloc(&@$, OP_AND, $1, $3); } ; exclusive_or_expr : and_expr - | exclusive_or_expr CARET and_expr + | exclusive_or_expr CARET and_rhs_expr { $$ = binop_expr_alloc(&@$, OP_XOR, $1, $3); } ; inclusive_or_expr : exclusive_or_expr - | inclusive_or_expr '|' exclusive_or_expr + | inclusive_or_expr '|' exclusive_or_rhs_expr { $$ = binop_expr_alloc(&@$, OP_OR, $1, $3); } @@ -3473,10 +3473,6 @@ relational_expr : expr /* implicit */ rhs_expr { $$ = relational_expr_alloc(&@2, $2, $1, $3); } - | expr relational_op '(' rhs_expr ')' - { - $$ = relational_expr_alloc(&@2, $2, $1, $4); - } ; list_rhs_expr : basic_rhs_expr COMMA basic_rhs_expr @@ -3660,6 +3656,7 @@ primary_rhs_expr : symbol_expr { $$ = $1; } BYTEORDER_HOST_ENDIAN, sizeof(data) * BITS_PER_BYTE, &data); } + | '(' basic_rhs_expr ')' { $$ = $2; } ; relational_op : EQ { $$ = OP_EQ; } -- cgit v1.2.3