Skip to content

fix: Changed 'equal_range()' + loop by 'find()' in resolveFirst() methods #3117

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

Merged
merged 2 commits into from
Jul 31, 2024

Conversation

airween
Copy link
Member

@airween airween commented Mar 29, 2024

This PR fixes SonarCloud issues in these files:

Summary: AnchoredSetVariable and InMemoryCollection types are derived from std::unordered_multimap.

Both type has a resolveFirst(key) method (AnchoredSetVariable, InMemoryCollection), which finds the first occurrence of key in the collection.

The current implemented version uses equal_range() (doc) to find the key in a loop, and breaks from that after first match. This C++ collection has another method to find it where we don't need any loop, that's the find() (doc).

@airween airween added the 3.x Related to ModSecurity version 3.x label Mar 29, 2024
@airween airween self-assigned this Mar 29, 2024
@airween airween requested a review from MirkoDziadzka March 29, 2024 17:06
Copy link

Quality Gate Passed Quality Gate passed

Issues
0 New issues
0 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
0.0% Duplication on New Code

See analysis details on SonarCloud

Copy link
Contributor

@fzipi fzipi left a comment

Choose a reason for hiding this comment

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

LGTM. I was looking if we can move the lock inside the if (before setting the value/expiration), but I guess the element found could be removed between the find step and the actual modification.

@airween airween merged commit 4b38435 into owasp-modsecurity:v3/master Jul 31, 2024
41 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.x Related to ModSecurity version 3.x
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants