Code

store_lookup: Fixed parsing of invalid compare expressions.
authorSebastian Harl <sh@tokkee.org>
Sun, 5 Oct 2014 16:19:39 +0000 (18:19 +0200)
committerSebastian Harl <sh@tokkee.org>
Sun, 5 Oct 2014 17:19:13 +0000 (19:19 +0200)
Previously, expressions like 'host.foo != 123' would be silently accepted by
the parser.

Added test cases to reproduce and catch the problem.

src/core/store_lookup.c
t/unit/core/store_lookup_test.c

index 86acd10ea17ccf0a05ca7a7d1faeda5b09c52446..d53bd58f35d743228ee054ccdfdd530e94360f6f 100644 (file)
@@ -1001,6 +1001,8 @@ sdb_store_matcher_parse_cmp(const char *obj_type, const char *attr,
                return NULL;
        if (value.type != SDB_TYPE_STRING) {
                sdb_data_free_datum(&value);
+               if (type != SDB_ATTRIBUTE)
+                       return NULL;
                return parse_attr_cmp(attr, op, expr);
        }
 
index b356fa0dd7b95858bddc93767a26ce4890136d23..754eb13f18808fba615ed1e809ac4d4b39a526e7 100644 (file)
@@ -532,10 +532,11 @@ END_TEST
 
 START_TEST(test_parse_cmp)
 {
-       sdb_data_t hostname   = { SDB_TYPE_STRING, { .string = "hostname" } };
-       sdb_data_t metricname = { SDB_TYPE_STRING, { .string = "metricname" } };
-       sdb_data_t srvname    = { SDB_TYPE_STRING, { .string = "srvname" } };
-       sdb_data_t attrname   = { SDB_TYPE_STRING, { .string = "attrname" } };
+       sdb_data_t hostname   = { SDB_TYPE_STRING,  { .string  = "hostname" } };
+       sdb_data_t metricname = { SDB_TYPE_STRING,  { .string  = "metricname" } };
+       sdb_data_t srvname    = { SDB_TYPE_STRING,  { .string  = "srvname" } };
+       sdb_data_t attrname   = { SDB_TYPE_STRING,  { .string  = "attrname" } };
+       sdb_data_t attrvalue  = { SDB_TYPE_INTEGER, { .integer = 4711 } };
 
        sdb_store_matcher_t *check;
 
@@ -554,6 +555,8 @@ START_TEST(test_parse_cmp)
                { "host",      NULL,   "!~", &hostname,   MATCHER_NOT },
                { "host",      "attr", "=",  &hostname,   -1 },
                { "host",      "attr", "!=", &hostname,   -1 },
+               { "host",      "attr", "!=", &attrvalue,  -1 },
+               { "host",      "attr", "<=", &attrvalue,  -1 },
                { "host",      NULL,   "&^", &hostname,   -1 },
                { "host",      NULL,   "<",  &hostname,   -1 },
                { "host",      NULL,   "<=", &hostname,   -1 },
@@ -566,6 +569,8 @@ START_TEST(test_parse_cmp)
                { "metric",    NULL,   "!~", &metricname, MATCHER_NOT },
                { "metric",    "attr", "=",  &metricname, -1 },
                { "metric",    "attr", "!=", &metricname, -1 },
+               { "metric",    "attr", "!=", &attrvalue,  -1 },
+               { "metric",    "attr", "<=", &attrvalue,  -1 },
                { "metric",    NULL,   "&^", &metricname, -1 },
                { "metric",    NULL,   "<",  &metricname, -1 },
                { "metric",    NULL,   "<=", &metricname, -1 },
@@ -578,6 +583,8 @@ START_TEST(test_parse_cmp)
                { "service",   NULL,   "!~", &srvname,    MATCHER_NOT },
                { "service",   "attr", "=",  &srvname,    -1 },
                { "service",   "attr", "!=", &srvname,    -1 },
+               { "service",   "attr", "!=", &attrvalue,  -1 },
+               { "service",   "attr", "<=", &attrvalue,  -1 },
                { "service",   NULL,   "&^", &srvname,    -1 },
                { "service",   NULL,   "<",  &srvname,    -1 },
                { "service",   NULL,   "<=", &srvname,    -1 },