Repository navigation
mod_proxy_balancer: Fix a read past the end of the string when looking up the sticky session route. - #843
Open
alepacheco wants to merge 2 commits into
Open
mod_proxy_balancer: Fix a read past the end of the string when looking up the sticky session route.#843alepacheco wants to merge 2 commits into
alepacheco wants to merge 2 commits into
Conversation
…g up the sticky session route. * modules/proxy/mod_proxy_balancer.c (get_path_param, get_cookie_param): Use a separate pointer to step over the parameter name and its '=', leaving the loop variable where strstr() found the name. When the name was at the end of the URL or Cookie header with no value after it, the loop variable was left on (or one past) the terminating NUL, so the next strstr(p + 1, name) started reading after the end of the string. The next search now also starts one character into the previous match, so a name that overlaps an earlier partial match is no longer skipped. (get_path_param): Return no route for an empty name, as configured by "stickysession=NAME|", which strstr() would otherwise match up to and past the terminating NUL. * changes-entries/balancer-sticky-overread.txt: Add entry.
Collaborator
Please do! |
* test/modules/proxy/test_01_http.py (test_proxy_01_004): Check that the route is taken from the stickysession cookie and query string parameter, and that a session name without a value selects no route.
Author
|
Added |
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.
get_path_param() and get_cookie_param() advance the for-loop variable over the parameter name and its '=' inside the loop body, and the loop increment then calls strstr(p + 1, name). When the sticky session name is the last thing in the URL or Cookie header and has no value after it (for example
Cookie: a=b; JSESSIONIDor/app;jsessionid=), the variable is left on or past the terminating NUL, and the next strstr() starts reading after the end of the string.This change steps over the name with a separate pointer, so the loop variable always stays where strstr() found the name and the next search starts inside the string. The returned values are otherwise unchanged, with one exception: a match that overlaps an earlier partial match is no longer skipped. get_path_param() also now returns no route for an empty name, which
stickysession=NAME|configures and which strstr() would match at every position up to and past the NUL.These are the only loops of this shape in server/ and modules/.
I checked the old and new versions of both functions with exact-size heap buffers under ASan. The old ones overflow on the inputs above, and the new ones return the same values for the other cases. The test/modules/proxy suite passes. I can add a pyhttpd test for a balancer with stickysession if you'd like one.