Add integer overflow checks to apreq parameter and cookie allocation#616
Open
kodareef5 wants to merge 2 commits intoapache:trunkfrom
Open
Add integer overflow checks to apreq parameter and cookie allocation#616kodareef5 wants to merge 2 commits intoapache:trunkfrom
kodareef5 wants to merge 2 commits intoapache:trunkfrom
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
apreq_param_make(),apreq_param_decode(),apreq_param_encode(), andapreq_cookie_make()compute allocation sizes asnlen + vlen + constantwithout checking for integer overflow. On platforms wheresize_tis 32-bit, large parameter or cookie values can cause the sum to wrap, resulting in undersized allocation.This adds overflow checks before each
apr_palloccall:apreq_param_make(server/apreq_param.c:38): checksnlen + vlen + 1 + sizeof *paramapreq_param_decode(server/apreq_param.c:84): same patternapreq_param_encode(server/apreq_param.c:144): checksnlen + dlenaddition and3 * summultiplicationapreq_cookie_make(server/apreq_cookie.c:143): checksnlen + vlen + 1 + sizeof *cOn overflow, each function returns
NULL(orAPR_ENOMEMforapreq_param_decode), consistent with existing allocation failure handling.