Skip to content
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

src: fix IsIPAddress for IPv6 #53400

Conversation

huseyinacacak-janea
Copy link
Contributor

I've investigated and found a fix to the related issue as follows:
host keeps the host address which is [::] in our case. Then, it is copied to a char array (ipv6_str) to remove brackets. However, when adding a null-terminator, the index is written wrong. The length should have been decreased by 2 to add a null terminator.

Fixes: #47427

Fix the bug when copying IPv6 host to a variable to remove brackets.

Fixes: nodejs#47427
@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. inspector Issues and PRs related to the V8 inspector protocol needs-ci PRs that need a full CI run. labels Jun 10, 2024
@@ -192,7 +192,7 @@ static bool IsIPAddress(const std::string& host) {
// Parse the IPv6 address to ensure it is syntactically valid.
char ipv6_str[INET6_ADDRSTRLEN];
std::copy(host.begin() + 1, host.end() - 1, ipv6_str);
ipv6_str[host.length()] = '\0';
ipv6_str[host.length() - 2] = '\0';
Copy link
Member

@anonrig anonrig Jun 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A better approach is to use Ada parser and validate if it is IPv6

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The IsIPAddress function is invoked by the IsAllowedHost function, which accepts a host parameter. Typically, the host represents an IP address that may include a port number. For instance, in the test case found here, the host is solely an IP address.

Upon reviewing the Ada parser, it appears to be designed primarily for parsing URLs. So, I can't use it here like this: ada::parse(host).

Is there a potential method to adapt the Ada parser for use with IP addresses?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is a bug fix, keeping the patch minimal is a good idea. Refactoring to use Ada or some entirely different validation instead does not need to happen in this PR.

Copy link
Member

@tniessen tniessen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch.

@tniessen tniessen added request-ci Add this label to start a Jenkins CI on a PR. author ready PRs that have at least one approval, no pending requests for changes, and a CI started. labels Jun 11, 2024
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Jun 11, 2024
@nodejs-github-bot
Copy link
Collaborator

@tniessen tniessen added the commit-queue Add this label to land a pull request using GitHub Actions. label Jun 12, 2024
@nodejs-github-bot nodejs-github-bot removed the commit-queue Add this label to land a pull request using GitHub Actions. label Jun 12, 2024
@nodejs-github-bot nodejs-github-bot merged commit 73fa9ab into nodejs:main Jun 12, 2024
67 checks passed
@nodejs-github-bot
Copy link
Collaborator

Landed in 73fa9ab

targos pushed a commit that referenced this pull request Jun 20, 2024
Fix the bug when copying IPv6 host to a variable to remove brackets.

Fixes: #47427
PR-URL: #53400
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: Richard Lau <rlau@redhat.com>
eliphazbouye pushed a commit to eliphazbouye/node that referenced this pull request Jun 20, 2024
Fix the bug when copying IPv6 host to a variable to remove brackets.

Fixes: nodejs#47427
PR-URL: nodejs#53400
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: Richard Lau <rlau@redhat.com>
bmeck pushed a commit to bmeck/node that referenced this pull request Jun 22, 2024
Fix the bug when copying IPv6 host to a variable to remove brackets.

Fixes: nodejs#47427
PR-URL: nodejs#53400
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: Richard Lau <rlau@redhat.com>
marco-ippolito pushed a commit that referenced this pull request Jul 19, 2024
Fix the bug when copying IPv6 host to a variable to remove brackets.

Fixes: #47427
PR-URL: #53400
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: Richard Lau <rlau@redhat.com>
marco-ippolito pushed a commit that referenced this pull request Jul 19, 2024
Fix the bug when copying IPv6 host to a variable to remove brackets.

Fixes: #47427
PR-URL: #53400
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: Richard Lau <rlau@redhat.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
author ready PRs that have at least one approval, no pending requests for changes, and a CI started. c++ Issues and PRs that require attention from people who are familiar with C++. inspector Issues and PRs related to the V8 inspector protocol needs-ci PRs that need a full CI run.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

flaky InspectorSocketTest.HostIPv6NonRoutable
5 participants