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 binary check expr is equal #1952

Merged
merged 2 commits into from
Jul 11, 2024
Merged

Conversation

mstemm
Copy link
Contributor

@mstemm mstemm commented Jul 11, 2024

What type of PR is this?

Uncomment one (or more) /kind <> lines:

/kind bug

/kind cleanup

/kind design

/kind documentation

/kind failing-test

/kind feature

Any specific area of the project related to this PR?

Uncomment one (or more) /area <> lines:

/area API-version

/area build

/area CI

/area driver-kmod

/area driver-bpf

/area driver-modern-bpf

/area libscap-engine-bpf

/area libscap-engine-gvisor

/area libscap-engine-kmod

/area libscap-engine-modern-bpf

/area libscap-engine-nodriver

/area libscap-engine-noop

/area libscap-engine-source-plugin

/area libscap-engine-savefile

/area libscap

/area libpman

/area libsinsp

/area tests

/area proposals

Does this PR require a change in the driver versions?

/version driver-API-version-major

/version driver-API-version-minor

/version driver-API-version-patch

/version driver-SCHEMA-version-major

/version driver-SCHEMA-version-minor

/version driver-SCHEMA-version-patch

What this PR does / why we need it:

Fix a bug in libsinsp::filter::ast::binary_check_expr::is_equal(). The method should compare the operators but isn't. So an expression evt.num >= 0 is mistakenly being considered equal to evt.num = 0

Which issue(s) this PR fixes:

Fixes #

Special notes for your reviewer:

Does this PR introduce a user-facing change?:

Fix a bug in libsinsp::filter::ast::binary_check_expr::is_equal(), where two binary check expressions were considered equal even if they had different operators. For example evt.num >= 0 was mistakenly considered equal to evt.num = 0.

Fix a bug in binary_check_expr::is_equal()--the comparison should also
compare the operators in addition to both sides.

Signed-off-by: Mark Stemm <mark.stemm@gmail.com>
Create two expressions with the same lhs/rhs but different ops, and
ensure that is_equal() returns false.

Signed-off-by: Mark Stemm <mark.stemm@gmail.com>
Copy link

Perf diff from master - unit tests

     9.94%     +0.95%  [.] sinsp_parser::reset
     7.87%     -0.94%  [.] sinsp::next
     3.16%     +0.92%  [.] sinsp_evt::load_params
     1.19%     -0.48%  [.] sinsp_evt::get_direction
     1.09%     -0.43%  [.] libsinsp::events::is_unknown_event
     0.88%     +0.43%  [.] std::vector<sinsp_evt_param, std::allocator<sinsp_evt_param> >::emplace_back<sinsp_evt*, unsigned int&, char const*, unsigned long&>
     0.50%     -0.38%  [.] get_cgroup_subsystems_v2
     4.66%     -0.37%  [.] sinsp_evt::get_type
     2.97%     +0.37%  [.] sinsp_thread_manager::get_thread_ref
     0.62%     -0.34%  [.] copy_and_sanitize_path

Perf diff from master - scap file

    13.72%     +6.56%  [.] sinsp_filter_check::tostring
    14.05%     -3.84%  [.] sinsp_evt_formatter::tostring_withformat
     3.11%     +2.60%  [.] std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_construct<char*>
     3.52%     +2.45%  [.] sinsp_filter_check::rawval_to_string
     6.99%     +2.27%  [.] sinsp_filter_check::extract_nocache
    10.57%     -2.16%  [.] sinsp_evt::get_param_as_str
     7.04%     -1.89%  [.] rawstring_check::extract_single
     7.03%     -1.89%  [.] std::_Hashtable<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, std::shared_ptr<sinsp_container_info const> >, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, std::shared_ptr<sinsp_container_info const> > >, std::__detail::_Select1st, std::equal_to<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::hash<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, std::__detail::_Prime_rehash_policy, std::__detail::_Hashtable_traits<true, false, true> >::_M_find_before_node
     6.95%     -1.85%  [.] sinsp_threadinfo::~sinsp_threadinfo
     6.45%     -1.62%  [.] libsinsp::runc::match_container_id

Heap diff from master - unit tests

total runtime: -0.10s.
calls to allocation functions: -633 (6459/s)
temporary memory allocations: -161 (1642/s)
peak heap memory consumption: -661B
peak RSS (including heaptrack overhead): 0B
total memory leaked: 0B

Heap diff from master - scap file

total runtime: 0.00s.
calls to allocation functions: 0 (0/s)
temporary memory allocations: 0 (0/s)
peak heap memory consumption: 0B
peak RSS (including heaptrack overhead): 0B
total memory leaked: 0B

Copy link
Contributor

@gnosek gnosek left a comment

Choose a reason for hiding this comment

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

LGTM. For an extra gold star, we could use a positive test (evt.num=0 is equal to evt.num = 0)

@poiana
Copy link
Contributor

poiana commented Jul 11, 2024

LGTM label has been added.

Git tree hash: 969c0d28bfd103dca403c0c7711ecdd916816512

Copy link
Contributor

@jasondellaluce jasondellaluce left a comment

Choose a reason for hiding this comment

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

/approve

@poiana
Copy link
Contributor

poiana commented Jul 11, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: gnosek, jasondellaluce, mstemm

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:
  • OWNERS [gnosek,jasondellaluce,mstemm]

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@jasondellaluce
Copy link
Contributor

/milestone 0.18.0

@poiana poiana added this to the 0.18.0 milestone Jul 11, 2024
@poiana poiana merged commit d8b5b2e into master Jul 11, 2024
42 of 43 checks passed
@poiana poiana deleted the fix-binary_check_expr_is_equal branch July 11, 2024 09:16
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.

4 participants