Skip to content

IIS: fix Content-Length formatting (correct printf specifier + full buffer size) - #3620

Open
A13501350 wants to merge 1 commit into
owasp-modsecurity:v2/masterfrom
A13501350:fix/iis-content-length-format
Open

IIS: fix Content-Length formatting (correct printf specifier + full buffer size)#3620
A13501350 wants to merge 1 commit into
owasp-modsecurity:v2/masterfrom
A13501350:fix/iis-content-length-format

Conversation

@A13501350

Copy link
Copy Markdown

Summary

Fixes the Content-Length header value being corrupted/truncated in the IIS module when ModSecurity has to synthesize it (only-response, non-chunked case).

Two defects were fixed in iis/mymodule.cpp:

  • ulTotalLength is a ULONGLONG, but was printed with "%d" (32-bit int). printf only consumed the low 32 bits, producing a wrong header for response bodies larger than ~2 GiB. Now uses "%llu".
  • The two other call sites format an unsigned int length with "%d"; changed to "%u".
  • StringCchPrintfA's cchDest was passed as sizeof(szLength)/sizeof(CHAR) - 1 (20), which can only hold 19 digits + null and would truncate a 20-digit 64-bit value. Now passes the full buffer size (21, which includes the null terminator).

Fixes

Closes #3619

Changed locations

  • iis/mymodule.cpp:644ulTotalLength (ULONGLONG) -> "%llu"
  • iis/mymodule.cpp:1142length (unsigned int) -> "%u"
  • iis/mymodule.cpp:1230length (unsigned int) -> "%u"

All three now pass sizeof(szLength) / sizeof(CHAR) as the destination size.

@coderabbitai

coderabbitai Bot commented Aug 27, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: fc82eb0f-5bf5-4611-b884-c50f9d1b27e5

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@sonarqubecloud

Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
C Maintainability Rating on New Code (required ≥ A)

See analysis details on SonarQube Cloud

Catch issues before they fail your Quality Gate with our IDE extension SonarQube for IDE

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