Skip to content

Add integer overflow checks to apreq parameter and cookie allocation#616

Open
kodareef5 wants to merge 2 commits intoapache:trunkfrom
kodareef5:fix-apreq-overflow
Open

Add integer overflow checks to apreq parameter and cookie allocation#616
kodareef5 wants to merge 2 commits intoapache:trunkfrom
kodareef5:fix-apreq-overflow

Conversation

@kodareef5
Copy link

apreq_param_make(), apreq_param_decode(), apreq_param_encode(), and apreq_cookie_make() compute allocation sizes as nlen + vlen + constant without checking for integer overflow. On platforms where size_t is 32-bit, large parameter or cookie values can cause the sum to wrap, resulting in undersized allocation.

This adds overflow checks before each apr_palloc call:

  • apreq_param_make (server/apreq_param.c:38): checks nlen + vlen + 1 + sizeof *param
  • apreq_param_decode (server/apreq_param.c:84): same pattern
  • apreq_param_encode (server/apreq_param.c:144): checks nlen + dlen addition and 3 * sum multiplication
  • apreq_cookie_make (server/apreq_cookie.c:143): checks nlen + vlen + 1 + sizeof *c

On overflow, each function returns NULL (or APR_ENOMEM for apreq_param_decode), consistent with existing allocation failure handling.

ap_escape_path_segment, ap_os_escape_path, and ap_escape_urlencoded
allocate output buffers using 3 * strlen(input) + constant without
checking for overflow. On platforms where size_t is 32-bit, large
inputs cause the multiplication to wrap, resulting in undersized
allocation.

The HTML escape function ap_escape_html2 in the same file already
has overflow protection (abort on overflow). Apply the same pattern
to the three URL escape functions for consistency.
apreq_param_make(), apreq_param_decode(), apreq_param_encode(), and
apreq_cookie_make() compute allocation sizes as nlen + vlen + constant
without checking for overflow. On platforms where size_t is 32-bit,
large parameter values can cause the sum to wrap, resulting in
undersized allocation.

Add overflow checks before each allocation, returning NULL or
APR_ENOMEM on overflow. The URL-encode path (apreq_param_encode)
also checks the 3 * (nlen + dlen) multiplication.
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