Fix URL parser delimiter-order underflow#269
Open
idrassi wants to merge 2 commits into
Open
Conversation
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.
Summary
Fixes memory-safety and authority-boundary bugs in
url_parse.The parser locates the
#,?, and;delimiters, then computes each component's length as a pointer difference between the delimiter position and a runningendpointer, casting the result touint32_tand passing it tostr_cn.Previously, when delimiters appeared in an order that did not match the parser's fixed processing sequence (fragment, then query, then params),
endcould be reassigned to a position before a later-processed delimiter. The subtractionend - delim_pos - 1then underflowed, the cast wrapped to a value nearUINT32_MAX, andstr_cn()was asked to copy a huge slice from a pointer near the end of caller-controlled input.The parser now only processes
#,?, and;when the delimiter is still inside the active[path_pos, end)span, and delimiter searches start from the path instead of the authority.This also fixes authority/path boundary handling:
@is only treated as userinfo when it appears inside the authority span, before the first/,?, or#@in the path, query, or fragment no longer rewrites the host/user splitExample inputs
These no longer trigger wrapped component lengths or authority misparsing:
http://host/path#frag?queryhttp://host/path#frag;paramshttp://host/path?query;notparamshttp://host;param/pathhttp://host/path@namehttp://host/path?email=a@bhttp://host/path#frag@tag