Skip to content

Commit

Permalink
filter_rewrite_tag: abort when infinite loop setting
Browse files Browse the repository at this point in the history
  Some match rules causes infinite loop.
  This fix to prevent these settings.
    e.g. 'Match *' , 'Match ****'

Signed-off-by: Takahiro Yamashita <[email protected]>
  • Loading branch information
nokute78 authored and edsiper committed Oct 20, 2021
1 parent 0c4f3f0 commit c130edb
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions plugins/filter_rewrite_tag/rewrite_tag.c
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,20 @@ static int process_config(struct flb_rewrite_tag *ctx)
return 0;
}

static int is_wildcard(char* match)
{
size_t len = strlen(match);
size_t i;

/* '***' should be ignored. So we check every char. */
for (i=0; i<len; i++) {
if (match[i] != '*') {
return 0;
}
}
return 1;
}

static int cb_rewrite_tag_init(struct flb_filter_instance *ins,
struct flb_config *config,
void *data)
Expand All @@ -202,6 +216,11 @@ static int cb_rewrite_tag_init(struct flb_filter_instance *ins,
flb_errno();
return -1;
}
if (is_wildcard(ins->match)) {
flb_plg_error(ins, "'Match' causes infinite loop. abort.");
flb_free(ctx);
return -1;
}
ctx->ins = ins;
ctx->config = config;
mk_list_init(&ctx->rules);
Expand Down

0 comments on commit c130edb

Please sign in to comment.