Skip to content

Fix GCC -Wall warnings on Fedora/RHEL builds#3567

Open
mikelolasagasti wants to merge 21 commits into
owasp-modsecurity:v3/masterfrom
mikelolasagasti:fix-warnings
Open

Fix GCC -Wall warnings on Fedora/RHEL builds#3567
mikelolasagasti wants to merge 21 commits into
owasp-modsecurity:v3/masterfrom
mikelolasagasti:fix-warnings

Conversation

@mikelolasagasti
Copy link
Copy Markdown

what

  • Fix compiler warnings reported when building with GCC and Fedora/RHEL-style flags (-Wall, hardening, ...).
  • Each commit targets one warning class / location where practical.
  • Build log warnings reduced from ~1270 to ~57 (same Fedora 45 / 3.0.15 build); remainder left for follow-up PRs.

why

  • Clean build logs are just better.
  • Fewer noisy warnings makes real regressions easier to spot in CI/packaging builds.

references

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]

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_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 and size_t for
hex digit 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>
@sonarqubecloud
Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
10.9% Duplication on New Code (required ≤ 3%)

See analysis details on SonarQube Cloud

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant