Skip to content

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

Merged
evanlucas merged 1 commit into
nodejs:masterfrom
evanlucas:fixdnslookupService
Jan 25, 2016
Merged

evanlucas merged 1 commit into
nodejs:masterfrom
evanlucas:fixdnslookupService

Conversation

@evanlucas

Copy link
Copy Markdown
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
Comment thread lib/dns.js Outdated

Copy link
Copy Markdown
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
Copy Markdown
Member

LGTM

Comment thread lib/dns.js

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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

cjihrig commented Jan 24, 2016

Copy link
Copy Markdown
Contributor

LGTM with comments.

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

Copy link
Copy Markdown
Contributor Author

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

@cjihrig

cjihrig commented Jan 25, 2016

Copy link
Copy Markdown
Contributor

LGTM

1 similar comment
@r-52

r-52 commented Jan 25, 2016

Copy link
Copy Markdown
Contributor

LGTM

@evanlucas

Copy link
Copy Markdown
Contributor Author

@mscdex LGTY?

@mscdex

mscdex commented Jan 25, 2016

Copy link
Copy Markdown
Contributor

LGTM

@evanlucas

Copy link
Copy Markdown
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
Copy Markdown
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

jasnell commented Jan 27, 2016

Copy link
Copy Markdown
Member

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

@evanlucas

Copy link
Copy Markdown
Contributor Author

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

@cjihrig

cjihrig commented Jan 27, 2016

Copy link
Copy Markdown
Contributor

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

@jasnell

jasnell commented Jan 27, 2016

Copy link
Copy Markdown
Member

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
Copy Markdown
Member

Yeah, this is a bug fix over anything else

@rvagg

rvagg commented Feb 8, 2016

Copy link
Copy Markdown
Member

@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 pushed a commit that referenced this pull request Feb 17, 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>
MylesBorins pushed a commit that referenced this pull request Feb 18, 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>
@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.

8 participants