Skip to content

Hardening integer overflow guards in escape helper functions for atta…#671

Open
SABITHSAHEB wants to merge 5 commits into
apache:trunkfrom
SABITHSAHEB:server-util-integer-overflow-hardening
Open

Hardening integer overflow guards in escape helper functions for atta…#671
SABITHSAHEB wants to merge 5 commits into
apache:trunkfrom
SABITHSAHEB:server-util-integer-overflow-hardening

Conversation

@SABITHSAHEB

Copy link
Copy Markdown

server/util: Harden escape helpers against allocation size overflows

Summary

This patch adds integer overflow validation to several escape helper functions in server/util.c before calculating allocation sizes.

These functions derive buffer sizes from input lengths using expressions such as 3 * len + 1 and 10 * len. Without validation, extremely large values could cause arithmetic wraparound, resulting in an undersized allocation and potential memory corruption during subsequent writes.

Changes

  • Added overflow checks before allocation size calculations.
  • Prevented allocations when the computed size would overflow size_t.
  • Preserved existing behavior for valid inputs.
  • Added regression tests covering boundary and overflow cases.

Security Impact

This change hardens memory allocation logic against integer-overflow conditions that could otherwise lead to heap buffer overflows when processing unusually large inputs.

Testing

  • Built successfully with GCC and MSVC.
  • Added regression tests for safe boundary values and overflow conditions.
  • Verified normal behavior remains unchanged for valid inputs.

Notes

  • No API changes.
  • No new dependencies.
  • Backward compatible.

@notroj

notroj commented Jun 23, 2026

Copy link
Copy Markdown
Collaborator

Using ap_assert in these cases is correct, don't remove that, if these paths are reachable you are just introducing some new error path which would crash differently anyway. Don't add new such paths anywhere, just use ap_assert throughout.

Keep ap_assert for these size checks instead of adding new error-return
paths, and restore the asserts that were removed. Drop the unrelated
mod_core atoi changes and the cookie reverse-map sizing churn so this
stays focused on the escape helpers.
@SABITHSAHEB

Copy link
Copy Markdown
Author

Makes sense, reverted to ap_assert across the board: restored the ones I'd removed and used it for the new checks too instead of the error-return paths. I also pulled the unrelated mod_core atoi changes and the cookie reverse-map sizing churn so this stays focused on the escape helpers. Pushed.

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