Skip to content

fix overflow in allocation size calculation in apreq_param_make#636

Open
jmestwa-coder wants to merge 1 commit intoapache:trunkfrom
jmestwa-coder:apreq-param-size-overflow
Open

fix overflow in allocation size calculation in apreq_param_make#636
jmestwa-coder wants to merge 1 commit intoapache:trunkfrom
jmestwa-coder:apreq-param-size-overflow

Conversation

@jmestwa-coder
Copy link
Copy Markdown

Summary

Fix integer overflow in apreq_param_make() when computing the allocation size.

Root Cause

The allocation size was calculated using unchecked arithmetic:

nlen + vlen + 1 + sizeof(*param)

For sufficiently large values, this addition can overflow apr_size_t, leading to an incorrect (wrapped) allocation size.

Fix

Add bounds checks before performing the allocation:

  • Ensure nlen + vlen does not overflow
  • Ensure the final size including structure and terminator fits in apr_size_t
  • Use the validated size for allocation

Behavior

  • Valid inputs: unchanged
  • Overflow cases: function returns NULL (already handled by callers)

Impact

Ensures allocation size calculations are safe and do not rely on implicit assumptions about input sizes.

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