From d50007810e6b5278e9b0af174b4bc7e964150f67 Mon Sep 17 00:00:00 2001 From: Sebastian Harl Date: Mon, 28 Jul 2014 09:15:19 +0200 Subject: [PATCH] store_lookup: Catch invalid values when parsing a matcher. Added a unit-test exposing the segfault we would have seen previously. --- src/core/store_lookup.c | 3 +++ t/unit/core/store_lookup_test.c | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/src/core/store_lookup.c b/src/core/store_lookup.c index 0bb157c..8aa8ab0 100644 --- a/src/core/store_lookup.c +++ b/src/core/store_lookup.c @@ -818,6 +818,9 @@ sdb_store_matcher_parse_cmp(const char *obj_type, const char *attr, else return NULL; + if (! value) + return NULL; + if (value->type != SDB_TYPE_STRING) { if (type == SDB_ATTRIBUTE) return parse_attr_cmp(attr, op, value); diff --git a/t/unit/core/store_lookup_test.c b/t/unit/core/store_lookup_test.c index 351ae18..43bb1e5 100644 --- a/t/unit/core/store_lookup_test.c +++ b/t/unit/core/store_lookup_test.c @@ -421,6 +421,7 @@ START_TEST(test_parse_cmp) { "host", NULL, "<=", &hostname, -1 }, { "host", NULL, ">=", &hostname, -1 }, { "host", NULL, ">", &hostname, -1 }, + { "host", NULL, "=", NULL, -1 }, { "service", NULL, "=", &srvname, MATCHER_NAME }, { "service", NULL, "!=", &srvname, MATCHER_NOT }, { "service", NULL, "=~", &srvname, MATCHER_NAME }, @@ -432,6 +433,7 @@ START_TEST(test_parse_cmp) { "service", NULL, "<=", &srvname, -1 }, { "service", NULL, ">=", &srvname, -1 }, { "service", NULL, ">", &srvname, -1 }, + { "service", NULL, "=", NULL, -1 }, { "attribute", NULL, "=", &attrname, MATCHER_NAME }, { "attribute", NULL, "!=", &attrname, MATCHER_NOT }, { "attribute", NULL, "=~", &attrname, MATCHER_NAME }, @@ -440,11 +442,13 @@ START_TEST(test_parse_cmp) { "attribute", NULL, "<=", &attrname, -1 }, { "attribute", NULL, ">=", &attrname, -1 }, { "attribute", NULL, ">", &attrname, -1 }, + { "attribute", NULL, "=", NULL, -1 }, { "attribute", "attr", "=", &attrname, MATCHER_ATTR }, { "attribute", "attr", "!=", &attrname, MATCHER_NOT }, { "attribute", "attr", "=~", &attrname, MATCHER_ATTR }, { "attribute", "attr", "!~", &attrname, MATCHER_NOT }, { "attribute", "attr", "&^", &attrname, -1 }, + { "attribute", "attr", "<", NULL, -1 }, { "attribute", "attr", "<", &attrname, MATCHER_LT }, { "attribute", "attr", "<=", &attrname, MATCHER_LE }, /* { "attribute", "attr", "=", &attrname, MATCHER_EQ }, */ -- 2.30.2