Skip to content

Commit

Permalink
regex match: Fix unexpected match with empty meta data
Browse files Browse the repository at this point in the history
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: collectd#1930

Signed-off-by: Takuro Ashie <ashie@clear-code.com>
  • Loading branch information
ashie committed Jun 18, 2019
1 parent 021f428 commit d4f5388
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions src/match_regex.c
Expand Up @@ -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;
Expand Down

0 comments on commit d4f5388

Please sign in to comment.