From: Takuro Ashie Date: Tue, 18 Jun 2019 06:54:51 +0000 (+0900) Subject: regex match: Fix unexpected match with empty meta data X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=d4f53887527777296b0982af60f4c0fecdb2f0d9;p=collectd.git regex match: Fix unexpected match with empty meta data If a user set MetaData "foo" "bar" and a metric does not have meta data (vl->meta == NULL), it causes unexpected match. Existance of MetaData config should be checked before meta data in a metric. See also: #1930 Signed-off-by: Takuro Ashie --- diff --git a/src/match_regex.c b/src/match_regex.c index 4052ad55..99f0709b 100644 --- a/src/match_regex.c +++ b/src/match_regex.c @@ -336,21 +336,22 @@ static int mr_match(const data_set_t __attribute__((unused)) * ds, /* {{{ */ if (mr_match_regexen(m->type_instance, vl->type_instance) == FC_MATCH_NO_MATCH) return nomatch_value; - if (vl->meta != NULL) { - for (llentry_t *e = llist_head(m->meta); e != NULL; e = e->next) { - mr_regex_t *meta_re = (mr_regex_t *)e->value; - char *value; - int status = meta_data_get_string(vl->meta, e->key, &value); - if (status == (-ENOENT)) /* key is not present */ - return nomatch_value; - if (status != 0) /* some other problem */ - continue; /* error will have already been printed. */ - if (mr_match_regexen(meta_re, value) == FC_MATCH_NO_MATCH) { - sfree(value); - return nomatch_value; - } + for (llentry_t *e = llist_head(m->meta); e != NULL; e = e->next) { + mr_regex_t *meta_re = (mr_regex_t *)e->value; + char *value; + int status; + if (vl->meta == NULL) + return nomatch_value; + status = meta_data_get_string(vl->meta, e->key, &value); + if (status == (-ENOENT)) /* key is not present */ + return nomatch_value; + if (status != 0) /* some other problem */ + continue; /* error will have already been printed. */ + if (mr_match_regexen(meta_re, value) == FC_MATCH_NO_MATCH) { sfree(value); + return nomatch_value; } + sfree(value); } return match_value;