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

V3/remove this throw call transaction h #3104

Open
wants to merge 17 commits into
base: v3/master
Choose a base branch
from

Conversation

gberkes
Copy link

@gberkes gberkes commented Mar 6, 2024

Introducing the use of assertions to address throw; calls that lack try-catch blocks. Upon examining the caller code that utilized methods containing the questioned throw; calls, it became clear that, in the current state of development, there are no scenarios where execution could reach these throw; calls. However, we cannot guarantee this for future development. For instance, if someone attempts to use getCurrentMarker() without first verifying isInsideAMarker(), ModSecurity would encounter the throw; and terminate. The issue with the other throw; call is similar in that it is, fortunately, unreachable at the moment. However, it differs because this throw; is intended to handle a case that has not yet been developed.

Fortunately, I found an article titled "Effective Use of Assertions in C++" by Mike A. Martin in (ACM SIGPLAN Language Tips, page 3), which offers a neat way to handle such cases, specifically regarding argument validation and unreachable code. Link to the article.

Following the guidance from this article, I addressed the issues and also included modifications to enrich assert error messages. Furthermore, I updated configure.ac to maintain the usual build procedure and modified README.md to introduce the new configure flag.

gberkes and others added 6 commits March 1, 2024 08:49
…atements.

- SonarCloud analysis identified standalone `throw;` calls without accompanying `try-catch` blocks, used inconsistently as placeholders or for premature termination under specific conditions.
- Removed these `throw;` instances to prevent potential runtime issues in future development phases, where such configurations might inadvertently be created.
- Introduced `assert` statements as a more appropriate mechanism for asserting preconditions in the affected class member functions, ensuring clearer intent and safer code behavior during development.
Implemented a new configuration option --enable-assertions=[yes|no] within config.ac, enabling controlled inclusion of -DNDEBUG in CPPFLAGS. The default setting suppresses assertions (by adding -DNDEBUG to CPPFLAGS), preserving the original behavior. This enhancement allows for the optional enabling of assertions during development or debugging by setting --enable-assertions=yes, thereby excluding -DNDEBUG from CPPFLAGS.
gberkes added 2 commits March 27, 2024 14:42
Resolved a null pointer dereference error identified by `make check-static` due to an outdated suppression in 'test/cppcheck_suppressions.txt'. The suppression at line 57 was incorrectly referencing 'src/rule_with_actions.cc:244'. Updated this to 'src/rule_with_actions.cc:243' to align with the current codebase.

Additionally, removed suppressions for 'rethrowNoCurrentException' as identified by SonarCloud. This was possible due to the removal of standalone 'throw;' statements in the code.
@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
Copy link
Member

airween commented Mar 29, 2024

Just for the record: this PR fixes two SonarCloud issues in files:

I also added these references as conversation.

README.md Show resolved Hide resolved
headers/modsecurity/transaction.h Outdated Show resolved Hide resolved
src/rule_with_actions.cc Outdated Show resolved Hide resolved
Copy link

sonarcloud bot commented Apr 26, 2024

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

eduar-hte added a commit to eduar-hte/ModSecurity that referenced this pull request Apr 30, 2024
- These were initially not included in these changes, as they were
other PRs (owasp-modsecurity#3104 & owasp-modsecurity#3132) that address them.
@airween
Copy link
Member

airween commented May 3, 2024

Please pull the modifications from #3134, and apply this PR. Or you can resolve the conflicts here.

eduar-hte added a commit to eduar-hte/ModSecurity that referenced this pull request May 4, 2024
- These were initially not included in these changes, as they were
other PRs (owasp-modsecurity#3104 & owasp-modsecurity#3132) that address them.
@gberkes gberkes requested a review from airween May 24, 2024 08:56
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.

None yet

3 participants