Skip to content
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

conditionals: fix handling of empty string values #10172

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

niedbalski
Copy link
Collaborator

Summary

  • Allow empty string values for equality comparisons in conditionals
  • Add proper handling of string conditions in processor
  • Fix handling condition types in processor units
  • Add test cases for string condition handling and empty values

Fixes #10168

@leonardo-albertovich
Copy link
Collaborator

Please don't remove review requests in the future.

Copy link
Collaborator

@leonardo-albertovich leonardo-albertovich left a comment

Choose a reason for hiding this comment

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

Please change all the pointer validations to explicitly compare against NULL (not just the ones I marked).

@@ -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)

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?


/* Using cfl_variant_create_from_string instead of a non-existent cfl_variant_set_string */
variant = cfl_variant_create_from_string((char *)value);
if (!variant) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

If you are not doing anything (ie. reporting) if cfl_variant_create_from_string returns NULL why do you have this code? returning variant would be the same.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Modify filter conditions does not work when filter is used as input processor
2 participants