Fix GCC -Wall warnings on Fedora/RHEL builds - #3567
mikelolasagasti wants to merge 23 commits into
Conversation
905e100 to
5a76e19
Compare
|
Fixed 3 SonarCloud warnings. The "10.9% Duplication on New Code (required ≤ 3%)" Quality Gate is out of the scope of this PR. |
|
|
Hi @mikelolasagasti, could you pick these changes or update your branch? Thanks! |
There was a problem hiding this comment.
Pull request overview
This PR reduces GCC -Wall (Fedora/RHEL-style) build warnings across ModSecurity by addressing common warning sources (initializer reordering, signed/unsigned mismatches, unused variables, and safer string/offset handling) in core transaction/rules logic, operators, parser, utilities, and public headers.
Changes:
- Reordered constructor/base/member initializers and added explicit default member initialization to silence
-Wreorder/uninitialized warnings. - Replaced several
intloop/index/length variables withsize_t/std::string::size_type/ unsigned types and added casts where needed to silence sign/size warnings. - Fixed a correctness issue in
utf8_to_unicode(snprintfbuffer size) and made IP parsing more robust when no CIDR slash is present.
Reviewed changes
Copilot reviewed 19 out of 19 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| src/variables/variable.h | Reorders initializer lists to match declaration order (-Wreorder). |
| src/utils/string.h | Uses std::string::size_type for truncation length. |
| src/utils/msc_tree.cc | Fixes signed/unsigned warnings and avoids strchr(...)-buffer when no / is present. |
| src/transaction.cc | Fixes base/member init order and widens request-body length type. |
| src/rules_set.cc | Uses size_t for rule vector indexing. |
| src/request_body_processor/multipart.cc | Fixes signed/unsigned comparison for upload file limit. |
| src/parser/seclang-parser.yy | Removes unused local variables in grammar actions. |
| src/parser/driver.cc | Uses size_t for rule vector indexing. |
| src/operators/validate_url_encoding.cc | Uses uint64_t index to match input_length type. |
| src/operators/rx.h | Moves m_re initialization to in-class default initializer. |
| src/operators/rx_global.h | Moves m_re initialization to in-class default initializer. |
| src/operators/pm_from_file.cc | Uses size_t loop index when scanning comment prefix. |
| src/modsecurity.cc | Adds explicit casts for offset bounds checks when parsing highlight data. |
| src/actions/transformations/utf8_to_unicode.cc | Fixes snprintf size argument and uses size_t for derived lengths/loops. |
| src/actions/transformations/html_entity_decode.cc | Uses std::string::size_type for loop index. |
| src/actions/transformations/compress_whitespace.cc | Fixes pointer-diff type warning via explicit cast and clarifies changed type. |
| src/actions/init_col.cc | Uses std::string::size_type for find() result. |
| headers/modsecurity/intervention.h | Switches header-defined helpers from static to inline to reduce warnings. |
| headers/modsecurity/anchored_set_variable_translation_proxy.h | Uses vector size_type for indexing. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
5a76e19 to
d4122aa
Compare
d4122aa to
561e701
Compare
8d0207e to
a813652
Compare
|
@airween rebased against current master. Also added fixes for CoPilot findings (commits 21 & 22) and fixed the githab AI findings with with previous approach. |
|
@mikelolasagasti thanks - meanwhile there were some changes recently (see 3.0.16), could you pick up those modifications? For eg. utf8_to_unicode.cc is completely new. |
Yes - I think you should use the mentioned fix. Also please upgrade your git submodules - I've added a test case against that bug to secrules-language-tests repository too (which is a submodule - it was suspicious that i386 tests were success in the CI workflow). |
sorry, now I reviewed your changes and it seems it built on my previous changes, but yours are more strict - which is better. So I would accept your changes in case of file |
|
|
Added an extra commit to address the duplicated code issue that was already present in the code. With this SonarQube shows all green. |
|
@airween should be all green now |
Use vector::size_type for the loop index when iterating over resolved
variable values, avoiding a signed/unsigned comparison with size().
Fixes GCC -Wsign-compare:
../headers/modsecurity/anchored_set_variable_translation_proxy.h:46:31:
warning: comparison of integer expressions of different signedness:
'int' and 'std::vector<const modsecurity::VariableValue*>::size_type'
{aka 'long unsigned int'} [-Wsign-compare]
Signed-off-by: Mikel Olasagasti Uranga <mikel@olasagasti.info>
Mark intervention::{reset,clean,freeUrl,freeLog,free} as inline so they
are not emitted as unused static functions in every translation unit
that includes intervention.h.
Fixes GCC -Wunused-function:
../headers/modsecurity/intervention.h:39:17: warning: 'void
modsecurity::intervention::clean(...)' defined but not used
[-Wunused-function]
../headers/modsecurity/intervention.h:59:17: warning: 'void
modsecurity::intervention::free(...)' defined but not used
[-Wunused-function]
Signed-off-by: Mikel Olasagasti Uranga <mikel@olasagasti.info>
Use std::string::size_type for the length limit so it matches str.length() and assign()'s count parameter. Fixes GCC -Wsign-compare: ../src/utils/string.h:94:22: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' and 'int' [-Wsign-compare] Signed-off-by: Mikel Olasagasti Uranga <mikel@olasagasti.info>
Initialize the Variable base class before m_dictElement, matching member declaration order. Fixes GCC -Wreorder: ../src/variables/variable.h:635:17: warning: 'm_dictElement' will be initialized after base 'Variable' [-Wreorder] Signed-off-by: Mikel Olasagasti Uranga <mikel@olasagasti.info>
Initialize the Variable base class before m_r and m_regex, matching member declaration order. Fixes GCC -Wreorder: ../src/variables/variable.h:648:17: warning: 'm_regex' will be initialized after base 'Variable' [-Wreorder] Signed-off-by: Mikel Olasagasti Uranga <mikel@olasagasti.info>
Use std::string::size_type for the position returned by find(), avoiding comparison with std::string::npos as a signed int. Fixes GCC -Wsign-compare: actions/init_col.cc:37:19: warning: comparison of integer expressions of different signedness [-Wsign-compare] Signed-off-by: Mikel Olasagasti Uranga <mikel@olasagasti.info>
Cast parsed highlight offsets to size_t before comparing with content and variable lengths. Fixes GCC -Wsign-compare: modsecurity.cc:271:30: warning: comparison of integer expressions of different signedness [-Wsign-compare] modsecurity.cc:350:30: warning: comparison of integer expressions of different signedness [-Wsign-compare] Signed-off-by: Mikel Olasagasti Uranga <mikel@olasagasti.info>
Initialize the Operator base class before m_re, matching member declaration order. Fixes GCC -Wreorder: ../src/operators/rx.h:62:12: warning: 'm_re' will be initialized after base 'Operator' [-Wreorder] ../src/operators/rx_global.h:62:12: warning: 'm_re' will be initialized after base 'Operator' [-Wreorder] Signed-off-by: Mikel Olasagasti Uranga <mikel@olasagasti.info>
Use size_t for the rule loop index when comparing against rules->size(). Fixes GCC -Wsign-compare: rules_set.cc:147:23: warning: comparison of integer expressions of different signedness [-Wsign-compare] Signed-off-by: Mikel Olasagasti Uranga <mikel@olasagasti.info>
Drop dead `char z = name.at(0)` assignments from RUN_TIME_VAR_* grammar actions; the first character was never used. Fixes GCC -Wunused-variable: seclang-parser.yy:2591:14: warning: unused variable 'z' [-Wunused-variable] Signed-off-by: Mikel Olasagasti Uranga <mikel@olasagasti.info>
Align integer types for bit/count comparisons in CPTAddElement, remove an unused variable, and compute CIDR slash position safely in TreeAddIP. Fixes -Wsign-compare and -Wunused-variable in CPTAddElement and TreeAddIP. Signed-off-by: Mikel Olasagasti Uranga <mikel@olasagasti.info>
Use sizeof(unicode) for the hex snprintf buffer size, strlen() for the formatted hex digit length, and size_t for the length and loop indices. Fixes -Wsizeof-pointer-memaccess and -Wsign-compare in actions/transformations/utf8_to_unicode.cc. Signed-off-by: Mikel Olasagasti Uranga <mikel@olasagasti.info>
Use std::string::size_type for the copy loop index to match copy. Fixes GCC -Wsign-compare: actions/transformations/html_entity_decode.cc:157:28: warning: comparison of integer expressions of different signedness [-Wsign-compare] Signed-off-by: Mikel Olasagasti Uranga <mikel@olasagasti.info>
Cast the in-place compression length to std::string::size_type before comparing with value.length(). Fixes GCC -Wsign-compare: actions/transformations/compress_whitespace.cc:42:34: warning: comparison of integer expressions of different signedness [-Wsign-compare] Signed-off-by: Mikel Olasagasti Uranga <mikel@olasagasti.info>
Compare upload file count against SecUploadFileLimit using uint32_t on both sides. Fixes GCC -Wsign-compare: request_body_processor/multipart.cc:561:26: warning: comparison of integer expressions of different signedness [-Wsign-compare] Signed-off-by: Mikel Olasagasti Uranga <mikel@olasagasti.info>
Use uint64_t for the scan index to match input_length. Fixes -Wsign-compare in operators/validate_url_encoding.cc:36 and :38. Signed-off-by: Mikel Olasagasti Uranga <mikel@olasagasti.info>
Use size_t for the loop index when scanning characters before '#'. Fixes GCC -Wsign-compare: operators/pm_from_file.cc:36:27: warning: comparison of integer expressions of different signedness [-Wsign-compare] Signed-off-by: Mikel Olasagasti Uranga <mikel@olasagasti.info>
Use size_t for the rule index when checking for duplicate rule IDs. Fixes GCC -Wsign-compare: parser/driver.cc:111:27: warning: comparison of integer expressions of different signedness [-Wsign-compare] Signed-off-by: Mikel Olasagasti Uranga <mikel@olasagasti.info>
Initialize TransactionAnchoredVariables before m_logCbData in the member initializer list. Signed-off-by: Mikel Olasagasti Uranga <mikel@olasagasti.info>
Use uint64_t for reqbodyNoFilesLength when comparing against SecRequestBodyNoFilesLimit. Signed-off-by: Mikel Olasagasti Uranga <mikel@olasagasti.info>
Cast characters to unsigned char before passing them to std::isspace. The ctype functions require EOF or an unsigned char-representable value. Signed-off-by: Mikel Olasagasti Uranga <mikel@olasagasti.info>
Release the YAJL generator before returning from offset validation errors to avoid leaking it on malformed matchString input. Signed-off-by: Mikel Olasagasti Uranga <mikel@olasagasti.info>
This should address the SonarQube duplication without mixing in unrelated cleanup. Signed-off-by: Mikel Olasagasti Uranga <mikel@olasagasti.info>
396c327 to
7e7a96e
Compare
|
Navigate logical layers of code changes, visualize relationships, and explore their blast radius. No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (19)
💤 Files with no reviewable changes (1)
Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review. 📝 WalkthroughWalkthroughThe pull request updates size and index types across several code paths, centralizes Unicode escape formatting, adjusts offset and IP parsing checks, and changes selected initialization and declaration details. ChangesCode corrections
Priority: ➖ Normal Estimated code review effort: 3 (Moderate) | ~20 minutes Change: Refactor Suggested reviewers: Merge Risk: ⚪ Minimal · up to The warning fixes preserve the documented processing behavior and improve character handling and error-path cleanup. No actionable merge-blocking risk remains; merge after normal checks. Security Architecture ReviewSecurity architecture risk: 🔵 Low · up to The examined changes preserve input bounds and logging limits while improving cleanup on invalid offsets. No introduced security concern was established, but incomplete parser and external-consumer coverage leaves some uncertainty. Retained concerns Security review detailsSecurity Blast Radius
Trust Boundaries and Controls
Resilience and Maintainability Implications
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
|
@airween rebased |





what
-Wall, hardening, ...).why
references
Summary by CodeRabbit
Bug Fixes
Improvements