-
Notifications
You must be signed in to change notification settings - Fork 30.1k
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
Conversation
@@ -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'); |
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.
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 TypeError
s are thrown here though so not a biggie.
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') |
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 wonder if we could reuse isLegalPort()
from lib/net.js
.
EDIT: That would also requiring coercing the value.
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 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()
).
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 agree with accepting a string for the port for consistency, but will that make this semver-major since it is a behavior change?
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 would say so.
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.
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?
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 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).
LGTM with comments. |
120f525
to
85d9f2d
Compare
ok, nits addressed (minus checking that the port is in a valid range). PTAL |
LGTM |
1 similar comment
LGTM |
@mscdex LGTY? |
LGTM |
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>
85d9f2d
to
0f8e63c
Compare
Landed in 0f8e63c. Thanks! |
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>
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>
Just noting: commits that add new throws need to be marked as |
This was causing the process to abort previously. Should that still make it semver-major? |
I would say replacing an abort with a thrown exception is not semver-major. |
hmm.. good point. :-)... in fact, in that case it's likely appropriate for LTS also. |
Yeah, this is a bug fix over anything else |
@nodejs/lts cherry-picking this commit will bring over an assert for |
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>
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>
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