From 6851612d3942135a7d6febc7d70bd34b7ab6cfc5 Mon Sep 17 00:00:00 2001 From: Sebastian Harl Date: Sun, 19 Oct 2014 17:24:50 +0200 Subject: [PATCH] frontend/grammar: Fixed parsing of 'attribute[]'. That is, don't accept anything besides the string "attribute". Previously, [] was accepted as an attribute value. --- src/frontend/grammar.y | 9 +++++++++ t/unit/frontend/parser_test.c | 4 ++++ 2 files changed, 13 insertions(+) diff --git a/src/frontend/grammar.y b/src/frontend/grammar.y index cc0d5b9..78b45d2 100644 --- a/src/frontend/grammar.y +++ b/src/frontend/grammar.y @@ -528,6 +528,15 @@ expression: | IDENTIFIER '[' STRING ']' { + if (strcasecmp($1, "attribute")) { + char errmsg[strlen($1) + strlen($3) + 32]; + snprintf(errmsg, sizeof(errmsg), + YY_("unknown value %s[%s]"), $1, $3); + sdb_fe_yyerror(&yylloc, scanner, errmsg); + free($1); $1 = NULL; + free($3); $3 = NULL; + YYABORT; + } $$ = sdb_store_expr_attrvalue($3); free($1); $1 = NULL; free($3); $3 = NULL; diff --git a/t/unit/frontend/parser_test.c b/t/unit/frontend/parser_test.c index 8898e8b..134b50c 100644 --- a/t/unit/frontend/parser_test.c +++ b/t/unit/frontend/parser_test.c @@ -213,6 +213,10 @@ START_TEST(test_parse) { "LOOKUP hosts MATCHING " "attribute['foo'] = " "1.23 + 'foo'", -1, -1, 0 }, + { "LOOKUP hosts MATCHING " + "attr['foo'] = 1.23", -1, -1, 0 }, + { "LOOKUP hosts MATCHING " + "attr['foo'] IS NULL", -1, -1, 0 }, /* comments */ { "/* some comment */", -1, 0, 0 }, -- 2.30.2