Skip to content

conditionals: fix handling of empty string values #10172

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/flb_conditionals.c
Original file line number Diff line number Diff line change
@@ -66,8 +66,14 @@ static struct flb_condition_rule *rule_create(const char *field,
switch (op) {
case FLB_RULE_OP_EQ:
case FLB_RULE_OP_NEQ:
/* Allow empty string values for equality comparisons */
if (!value) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please modify this to explicitly compare with NULL.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, wouldn't this be covered by the conditional in line 62? (which should be modified to explicitly compare the pointer values with NULL)

return NULL;
}
break;
case FLB_RULE_OP_REGEX:
case FLB_RULE_OP_NOT_REGEX:
/* Regex patterns must not be empty */
if (!value || !((char *)value)[0]) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please modify this to explicitly compare with NULL.
Please refactor the second part of the term to make it clearer.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as before, since I don't see a loop or goto I don't understand why do we need to check that value is not NULL here as well, could you please clarify this?

return NULL;
}
7 changes: 6 additions & 1 deletion src/flb_processor.c
Original file line number Diff line number Diff line change
@@ -585,7 +585,12 @@ int flb_processor_unit_set_property(struct flb_processor_unit *pu, const char *k

/* Handle the "condition" property for processor units */
if (strcasecmp(k, "condition") == 0) {
return flb_processor_unit_set_condition(pu, v);
/* Only process if it's a structured map object */
if (v->type == CFL_VARIANT_KVLIST) {
return flb_processor_unit_set_condition(pu, v);
}
/* If string, ignore here - it will be handled by filter_modify */
return 0;
}

/* Handle normal properties */
621 changes: 369 additions & 252 deletions tests/internal/processor_conditional.c

Large diffs are not rendered by default.