From: Sebastian Harl Date: Sun, 19 Oct 2014 15:24:50 +0000 (+0200) Subject: frontend/grammar: Fixed parsing of 'attribute[]'. X-Git-Tag: sysdb-0.6.0~99 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=6851612d3942135a7d6febc7d70bd34b7ab6cfc5;p=sysdb.git frontend/grammar: Fixed parsing of 'attribute[]'. That is, don't accept anything besides the string "attribute". Previously, [] was accepted as an attribute value. --- 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 },