Code

frontend/grammar: Fixed parsing of 'attribute[<string>]'.
authorSebastian Harl <sh@tokkee.org>
Sun, 19 Oct 2014 15:24:50 +0000 (17:24 +0200)
committerSebastian Harl <sh@tokkee.org>
Sun, 19 Oct 2014 15:24:50 +0000 (17:24 +0200)
That is, don't accept anything besides the string "attribute". Previously,
<anything>[<string>] was accepted as an attribute value.

src/frontend/grammar.y
t/unit/frontend/parser_test.c

index cc0d5b94d475d6ccce027aab7e3601e957ecdc1a..78b45d295a1585fe93dfa9e1bb0e9b3bdd504879 100644 (file)
@@ -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;
index 8898e8b082852b5212fe307e76ece7a538dc251b..134b50cc54cb5c499d878210ca66013274faa287 100644 (file)
@@ -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 },