dns: throw a TypeError in lookupService with invalid port#4839
dns: throw a TypeError in lookupService with invalid port#4839evanlucas merged 1 commit intonodejs:masterfrom
Conversation
lib/dns.js
Outdated
There was a problem hiding this comment.
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.
|
LGTM |
There was a problem hiding this comment.
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.
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.
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.
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.
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: #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