-
Notifications
You must be signed in to change notification settings - Fork 871
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixes url parsing for .888 hosts #14588
Closed
Closed
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
diff --git a/url/url_canon_ip.cc b/url/url_canon_ip.cc | ||
index 1706377bd850a42989627f9aed4e7efbcb499b08..295cb6854e06bb8baf1c88598a1525d0b0517e62 100644 | ||
--- a/url/url_canon_ip.cc | ||
+++ b/url/url_canon_ip.cc | ||
@@ -142,6 +142,7 @@ CanonHostInfo::Family DoIPv4AddressToNumber(const CHAR* spec, | ||
// number. | ||
uint32_t component_values[4]; | ||
int existing_components = 0; | ||
+ bool host_ends_with_888 = false; | ||
|
||
int current_component_end = host.end(); | ||
int current_position = current_component_end; | ||
@@ -165,7 +166,11 @@ CanonHostInfo::Family DoIPv4AddressToNumber(const CHAR* spec, | ||
return CanonHostInfo::NEUTRAL; | ||
|
||
if (family != CanonHostInfo::IPV4) | ||
- return CanonHostInfo::BROKEN; | ||
+ return host_ends_with_888 ? CanonHostInfo::NEUTRAL | ||
+ : CanonHostInfo::BROKEN; | ||
+ | ||
+ if (existing_components == 0) | ||
+ host_ends_with_888 = component_values[0] == 888; | ||
|
||
++existing_components; | ||
|
||
@@ -175,7 +180,8 @@ CanonHostInfo::Family DoIPv4AddressToNumber(const CHAR* spec, | ||
|
||
// If there are more than 4 components, fail. | ||
if (existing_components == 4) | ||
- return CanonHostInfo::BROKEN; | ||
+ return host_ends_with_888 ? CanonHostInfo::NEUTRAL | ||
+ : CanonHostInfo::BROKEN; | ||
|
||
current_component_end = current_position - 1; | ||
--current_position; | ||
@@ -187,7 +193,8 @@ CanonHostInfo::Family DoIPv4AddressToNumber(const CHAR* spec, | ||
// within an 8-bit field. | ||
for (int i = existing_components - 1; i > 0; i--) { | ||
if (component_values[i] > std::numeric_limits<uint8_t>::max()) | ||
- return CanonHostInfo::BROKEN; | ||
+ return host_ends_with_888 ? CanonHostInfo::NEUTRAL | ||
+ : CanonHostInfo::BROKEN; | ||
address[existing_components - i - 1] = | ||
static_cast<unsigned char>(component_values[i]); | ||
} |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please also add
1.2.3.888
to check that it's a valid URL but not a valid IPv4 URL.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added in a6ecf5c
It actually didn't pass as I didn't cover residual bits case in parse(I wrongly assumed that was not .888 case)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now DoIPv4AddressToNumber never reports BROKEN when last component is .888
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is that the right behavior? I mean if you have
1.2.3.888
, which is not a valid IPv4 and try to convert this IPv4 URL to a number, it seems like it should fail because the input was not an IPv4 address in the first place, no?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For correct IPv4 address parser should say that it is exactly IPv4 address, so we don't break it
For Url parser now says it is not a broken ipv4 address, but something else.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see, so we now have this?
It might be worth adding
1.2.3.889
as a test case too just to make sure that we don't change that one.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added 692c0ff
also now checking for 888 ending being an exact string to avoid 888 in hex or oct form.