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

fix(userspace/libsinsp): solve issues with negate comparisons on ip and ipnet checks #1953

Merged
merged 1 commit into from
Jul 11, 2024
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion userspace/libsinsp/filter/ast.h
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,7 @@ struct SINSP_PUBLIC unary_check_expr: expr
bool is_equal(const expr* other) const override
{
auto o = dynamic_cast<const unary_check_expr*>(other);
return o != nullptr && left->is_equal(o->left.get());
return o != nullptr && left->is_equal(o->left.get()) && op == o->op;
}

std::unique_ptr<expr> left;
Expand Down
16 changes: 8 additions & 8 deletions userspace/libsinsp/filter_compare.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -650,41 +650,41 @@ bool flt_compare(cmpop op, ppm_param_type type, const void* operand1, const void
case PT_IPV4ADDR:
if (op2_len != sizeof(struct in_addr))
{
return false;
return op == CO_NE;
}
return flt_compare_ipv4addr(op, flt_cast<uint32_t, uint64_t>(operand1), flt_cast<uint32_t, uint64_t>(operand2));
case PT_IPV4NET:
if (op2_len != sizeof(ipv4net))
{
return false;
return op == CO_NE;
}
return flt_compare_ipv4net(op, (uint64_t)*(uint32_t*)operand1, (ipv4net*)operand2);
case PT_IPV6ADDR:
if (op2_len != sizeof(ipv6addr))
{
return false;
return op == CO_NE;
}
return flt_compare_ipv6addr(op, (ipv6addr *)operand1, (ipv6addr *)operand2);
case PT_IPV6NET:
if (op2_len != sizeof(ipv6net))
{
return false;
return op == CO_NE;
}
return flt_compare_ipv6net(op, (ipv6addr *)operand1, (ipv6net*)operand2);
case PT_IPADDR:
if(op1_len == sizeof(struct in_addr))
{
if (op2_len != sizeof(struct in_addr))
{
return false;
return op == CO_NE;
}
return flt_compare(op, PT_IPV4ADDR, operand1, operand2, op1_len, op2_len);
}
else if(op1_len == sizeof(struct in6_addr))
{
if (op2_len != sizeof(ipv6addr))
{
return false;
return op == CO_NE;
}
return flt_compare(op, PT_IPV6ADDR, operand1, operand2, op1_len, op2_len);
}
Expand All @@ -697,15 +697,15 @@ bool flt_compare(cmpop op, ppm_param_type type, const void* operand1, const void
{
if (op2_len != sizeof(ipv4net))
{
return false;
return op == CO_NE;
}
return flt_compare(op, PT_IPV4NET, operand1, operand2, op1_len, op2_len);
}
else if(op1_len == sizeof(struct in6_addr))
{
if (op2_len != sizeof(ipv6net))
{
return false;
return op == CO_NE;
}
return flt_compare(op, PT_IPV6NET, operand1, operand2, op1_len, op2_len);
}
Expand Down
Loading