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

dns: throw a TypeError in lookupService with invalid port #4839

Merged
merged 1 commit into from
Jan 25, 2016

Conversation

evanlucas
Copy link
Contributor

Previously, port was assumed to be a number and would cause an abort in
cares_wrap. This change throws a TypeError if port is not a number
before we actually hit C++.

Fixes: #4837

@evanlucas evanlucas added the dns Issues and PRs related to the dns subsystem. label Jan 24, 2016
@@ -189,6 +189,9 @@ exports.lookupService = function(host, port, callback) {
if (cares.isIP(host) === 0)
throw new TypeError('"host" argument needs to be a valid IP address');

if (typeof port !== 'number')
throw new TypeError('"port" argument must be a number');
Copy link
Member

Choose a reason for hiding this comment

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

Might be a good idea to add the failing value here:

throw new TypeError(`"port" argument must be a number, got ${port} instead.`);

That's not a regression from how other TypeErrors are thrown here though so not a biggie.

@benjamingr
Copy link
Member

LGTM

@@ -189,6 +189,9 @@ exports.lookupService = function(host, port, callback) {
if (cares.isIP(host) === 0)
throw new TypeError('"host" argument needs to be a valid IP address');

if (typeof port !== 'number')
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if we could reuse isLegalPort() from lib/net.js.

EDIT: That would also requiring coercing the value.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think it might be better to coerce and check the result with isFinite(). Allowing a port number as a string here would be consistent with other subsystems that allow such inputs (e.g. http.request()).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree with accepting a string for the port for consistency, but will that make this semver-major since it is a behavior change?

Copy link
Contributor

Choose a reason for hiding this comment

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

I would say so.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So, in that case, I think that we should at least throw a TypeError if port is not a number first, and then, in a separate PR, change it to coerce the value to a number and make sure it is in the proper port range as a semver-major change. Thoughts?

Copy link
Member

Choose a reason for hiding this comment

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

I definitely think coercion of numbers should be discussed first. I also think that this PR should go forward since it fixes a bug regardless of that issue (non-number ports aren't accepted as of today).

@cjihrig
Copy link
Contributor

cjihrig commented Jan 24, 2016

LGTM with comments.

@evanlucas evanlucas force-pushed the fixdnslookupService branch from 120f525 to 85d9f2d Compare January 25, 2016 13:58
@evanlucas
Copy link
Contributor Author

ok, nits addressed (minus checking that the port is in a valid range). PTAL

@cjihrig
Copy link
Contributor

cjihrig commented Jan 25, 2016

LGTM

1 similar comment
@r-52
Copy link
Contributor

r-52 commented Jan 25, 2016

LGTM

@evanlucas
Copy link
Contributor Author

@mscdex LGTY?

@mscdex
Copy link
Contributor

mscdex commented Jan 25, 2016

LGTM

@evanlucas
Copy link
Contributor Author

Previously, port was assumed to be a number and would cause an abort in
cares_wrap. This change throws a TypeError if port is not a number
before we actually hit C++.

Fixes: nodejs#4837
PR-URL: nodejs#4839
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Roman Klauke <romaaan.git@gmail.com>
Reviewed-By: Brian White <mscdex@mscdex.net>
@evanlucas evanlucas force-pushed the fixdnslookupService branch from 85d9f2d to 0f8e63c Compare January 25, 2016 21:16
@evanlucas evanlucas closed this Jan 25, 2016
@evanlucas evanlucas deleted the fixdnslookupService branch January 25, 2016 21:16
@evanlucas evanlucas merged commit 0f8e63c into nodejs:master Jan 25, 2016
@evanlucas
Copy link
Contributor Author

Landed in 0f8e63c. Thanks!

rvagg pushed a commit that referenced this pull request Jan 26, 2016
Previously, port was assumed to be a number and would cause an abort in
cares_wrap. This change throws a TypeError if port is not a number
before we actually hit C++.

Fixes: #4837
PR-URL: #4839
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Roman Klauke <romaaan.git@gmail.com>
Reviewed-By: Brian White <mscdex@mscdex.net>
benjamingr pushed a commit to benjamingr/io.js that referenced this pull request Jan 27, 2016
Previously, port was assumed to be a number and would cause an abort in
cares_wrap. This change throws a TypeError if port is not a number
before we actually hit C++.

Fixes: nodejs#4837
PR-URL: nodejs#4839
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Roman Klauke <romaaan.git@gmail.com>
Reviewed-By: Brian White <mscdex@mscdex.net>
@jasnell jasnell added the semver-major PRs that contain breaking changes and should be released in the next major version. label Jan 27, 2016
@jasnell
Copy link
Member

jasnell commented Jan 27, 2016

Just noting: commits that add new throws need to be marked as semver-major :-) label added!

@evanlucas
Copy link
Contributor Author

This was causing the process to abort previously. Should that still make it semver-major?

@cjihrig
Copy link
Contributor

cjihrig commented Jan 27, 2016

I would say replacing an abort with a thrown exception is not semver-major.

@jasnell
Copy link
Member

jasnell commented Jan 27, 2016

hmm.. good point. :-)... in fact, in that case it's likely appropriate for LTS also.

@jasnell jasnell added lts-watch-v4.x and removed semver-major PRs that contain breaking changes and should be released in the next major version. labels Jan 27, 2016
@benjamingr
Copy link
Member

Yeah, this is a bug fix over anything else

@rvagg
Copy link
Member

rvagg commented Feb 8, 2016

@nodejs/lts cherry-picking this commit will bring over an assert for Invalid argument in an error name. This will fail because that name is new, and semver-major, on master. The commit needs to be changed to test for invalid argument (lower-case).

@MylesBorins MylesBorins mentioned this pull request Feb 18, 2016
MylesBorins pushed a commit that referenced this pull request Mar 2, 2016
Previously, port was assumed to be a number and would cause an abort in
cares_wrap. This change throws a TypeError if port is not a number
before we actually hit C++.

Fixes: #4837
PR-URL: #4839
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Roman Klauke <romaaan.git@gmail.com>
Reviewed-By: Brian White <mscdex@mscdex.net>
scovetta pushed a commit to scovetta/node that referenced this pull request Apr 2, 2016
Previously, port was assumed to be a number and would cause an abort in
cares_wrap. This change throws a TypeError if port is not a number
before we actually hit C++.

Fixes: nodejs#4837
PR-URL: nodejs#4839
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Roman Klauke <romaaan.git@gmail.com>
Reviewed-By: Brian White <mscdex@mscdex.net>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dns Issues and PRs related to the dns subsystem.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants