Skip to content

Commit

Permalink
fix(userspace/libsinsp): solve issues with negate comparisons on ip a…
Browse files Browse the repository at this point in the history
…nd ipnet checks

Signed-off-by: Jason Dellaluce <[email protected]>
  • Loading branch information
jasondellaluce authored and poiana committed Jul 11, 2024
1 parent d8b5b2e commit ad46fd6
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
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

0 comments on commit ad46fd6

Please sign in to comment.