Skip to content

clean cppcheck warnings in the iis/ ext/ and mlogc/ directories#3596

Open
umprayz wants to merge 3 commits into
owasp-modsecurity:v2/masterfrom
umprayz:v2/cppcheck_0709
Open

clean cppcheck warnings in the iis/ ext/ and mlogc/ directories#3596
umprayz wants to merge 3 commits into
owasp-modsecurity:v2/masterfrom
umprayz:v2/cppcheck_0709

Conversation

@umprayz

@umprayz umprayz commented Jul 9, 2026

Copy link
Copy Markdown

what

  • This is a clean version of the PR: <V2/cppcheck 0702 clean V2/cppcheck 0702 clean #3595>
  • This pull request fixes the cppcheck warnings in all .c, .cpp and .h files within iis/ ext/ and mlogc/ directories.
  • These were added to the cppcheck command in the Makefile.am.

why

  • The changes did not changed any logic, and were based on the output of the cppcheck command.
  • Now, said command produces zero warnings in these three directories.
  • One other change was made in the api.c and api.h files in the standalone/ directory, in order to resolve a warning in these two function: modsecSetWriteBody() and modsecSetWriteResponse(). The mymodule.cpp uses them in its WriteResponseCallback() and WriteBodyCallback() functions.

references

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This pull request aims to make the codebase cppcheck-clean in the iis/, ext/, and mlogc/ directories (and updates the cppcheck Makefile target to scan them), primarily through const-correctness, null-safety, and warning suppressions. It also adjusts the standalone API write-callback signatures used by the IIS module.

Changes:

  • Expand make cppcheck to scan mlogc/, iis/, and ext/ in addition to standalone/.
  • Apply const-correctness and nullptr cleanups across IIS and extension code; adjust standalone write-callback signatures accordingly.
  • Address (some) warning-driven issues in mlogc (e.g., allocation checks, local variable scoping, const qualifiers).

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 9 comments.

Show a summary per file
File Description
Makefile.am Extends the cppcheck target to include mlogc/, iis/, and ext/.
standalone/api.h Changes write-callback setter prototypes to accept const char *buf.
standalone/api.c Changes write-callback setter definitions to accept const char *buf.
mlogc/mlogc.c Adjusts constness and local variable scoping; adds some warning suppressions and allocation-guarding.
iis/mymodule.cpp Replaces NULL with nullptr, tightens const usage, and updates write callbacks to const char *.
iis/moduleconfig.h Moves m_Config and adds a cppcheck suppression comment.
iis/moduleconfig.cpp Reworks exception handling assignments; includes comment updates and keeps constructor member init list.
iis/main.cpp Adds cppcheck suppression for a redundant assignment and adjusts comment placement.
ext/mod_var_remote_addr_port.c Makes variable parameters const where applicable.
ext/mod_op_strstr.c Adds const qualifiers and local initialization changes in Boyer–Moore–Horspool code and operator exec signature.
Comments suppressed due to low confidence (1)

mlogc/mlogc.c:707

  • start is still NULL when used in the pointer comparison p > start, which is undefined/meaningless and can break the newline-trimming logic. Compare against line (the start of the buffer) instead.
    /* Remove the trailing newline character. */
    p = (char *)line;
    while(*p != '\0') p++;
    if ((p > start)&&(*(p - 1) == '\n')) *(p - 1) = '\0';


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread mlogc/mlogc.c
Comment on lines 399 to +404
entry = (entry_t *)malloc(sizeof(entry_t));
entry->id = 0;
entry->line = strdup(data);
entry->line_size = strlen(entry->line);
if(entry != NULL){
entry->id = 0;
entry->line = strdup(data);
entry->line_size = strlen(entry->line);
}
Comment thread iis/moduleconfig.cpp
Comment thread iis/moduleconfig.cpp
Comment thread iis/moduleconfig.cpp Outdated
Comment thread iis/moduleconfig.cpp
Comment on lines 474 to +477
MODSECURITY_STORED_CONTEXT::MODSECURITY_STORED_CONTEXT():
m_bIsEnabled ( FALSE ),
m_pszPath( NULL ),
m_Config( NULL )
m_Config( NULL )
Comment thread iis/moduleconfig.h
Comment thread ext/mod_op_strstr.c
Comment thread standalone/api.c
Comment on lines +687 to 692
void modsecSetWriteBody(apr_status_t (*func)(request_rec *r, const char *buf, unsigned int length)) {
modsecWriteBody = func;
}

void modsecSetWriteResponse(apr_status_t (*func)(request_rec *r, char *buf, unsigned int length)) {
void modsecSetWriteResponse(apr_status_t (*func)(request_rec *r, const char *buf, unsigned int length)) {
modsecWriteResponse = func;
Comment thread iis/mymodule.cpp
Comment on lines +1110 to +1112
if (readcnt != nullptr) {
*readcnt = static_cast<unsigned int>(dwReadcnt);
}
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@sonarqubecloud

sonarqubecloud Bot commented Jul 9, 2026

Copy link
Copy Markdown

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.

2 participants