From: Sebastian Harl Date: Sun, 22 Jun 2014 12:21:50 +0000 (+0200) Subject: store: Don't allow name to be NULL when matching attributes. X-Git-Tag: sysdb-0.2.0~45 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=6ff17f75945794254382737d2f1c979e0d52387e;p=sysdb.git store: Don't allow name to be NULL when matching attributes. There's no real use-case for it imho and it's just a weird special case in the code. --- diff --git a/src/core/store_lookup.c b/src/core/store_lookup.c index e6e0a18..1630d3a 100644 --- a/src/core/store_lookup.c +++ b/src/core/store_lookup.c @@ -157,13 +157,14 @@ match_attr(sdb_store_matcher_t *m, sdb_store_base_t *obj) int status = 0; assert(m->type == MATCHER_ATTR); + assert(ATTR_M(m)->name); iter = sdb_llist_get_iter(SDB_STORE_OBJ(obj)->attributes); while (sdb_llist_iter_has_next(iter)) { sdb_attribute_t *attr = SDB_ATTR(sdb_llist_iter_get_next(iter)); char buf[sdb_data_strlen(&attr->value) + 1]; - if (ATTR_M(m)->name && strcasecmp(ATTR_M(m)->name, SDB_OBJ(attr)->name)) + if (strcasecmp(ATTR_M(m)->name, SDB_OBJ(attr)->name)) continue; if (sdb_data_format(&attr->value, buf, sizeof(buf), SDB_UNQUOTED) <= 0) @@ -449,6 +450,9 @@ sdb_store_name_matcher(int type, const char *name, _Bool re) sdb_store_matcher_t * sdb_store_attr_matcher(const char *name, const char *value, _Bool re) { + if (! name) + return NULL; + if (re) return M(sdb_object_create("attr-matcher", attr_type, name, NULL, value)); diff --git a/t/unit/core/store_lookup_test.c b/t/unit/core/store_lookup_test.c index 918fbef..c3f3b51 100644 --- a/t/unit/core/store_lookup_test.c +++ b/t/unit/core/store_lookup_test.c @@ -177,8 +177,6 @@ START_TEST(test_store_match_attr) int expected; } golden_data[] = { - { NULL, NULL, 0, 1 }, - { NULL, NULL, 1, 1 }, { "k1", NULL, 0, 1 }, { "k", NULL, 1, 0 }, { "1", NULL, 1, 0 }, @@ -188,10 +186,9 @@ START_TEST(test_store_match_attr) { "k3", NULL, 1, 0 }, { "k1", "v1", 0, 1 }, { "k1", "v1", 1, 1 }, + { "k1", "^v1$", 1, 1 }, { "k1", "v", 1, 1 }, { "k1", "1", 1, 1 }, - { NULL, "v1", 0, 1 }, - { NULL, "^v1$", 1, 1 }, { "k1", "v2", 0, 0 }, { "k1", "v2", 1, 0 }, { "k", "v1", 0, 0 },