-
Notifications
You must be signed in to change notification settings - Fork 29.8k
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
net: fix abort on bad address input #13726
Conversation
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.
LGTM with the tiny nit I’d phrase the commit message as fix abort
rather than fix segfault
, because that’s what it is (at least on POSIX, but it shouldn’t be a segfault on Windows either)
lib/net.js
Outdated
@@ -872,6 +872,10 @@ function internalConnect( | |||
|
|||
var err; | |||
|
|||
if (typeof address !== 'string') { | |||
throw new TypeError('Invalid address: ' + address); |
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.
because this is introducing a new error, it should use internal/errors
|
||
{ | ||
try { | ||
net.createConnection({ path: {} }); |
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.
Use assert.throws()
here.
Defensively marking as semver-major due to the new throw. Am argument could be made for patch tho because it would abort previously |
@jasnell I’m surprised … we tag error changes as semver-major because we know people might rely non-throwing behaviour, or existing errors and their messages, but I find it hard to believe people actively rely on processes aborting? |
It's not likely at all. As I said, an argument can be made that it's a patch, just need to make sure folks agree |
I agree that it is very unlikely that anyone would rely on that. It's actually already rare to trigger this in the first place and I think it would be good to backport this, if it's accepted as semver-patch. |
lib/net.js
Outdated
@@ -872,6 +873,10 @@ function internalConnect( | |||
|
|||
var err; | |||
|
|||
if (typeof address !== 'string') { |
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.
Can we move this to .connect()
instead, under the if (pipe)
check? internalConnect()
is also called for non-pipe connections and so it would be an unnecessary/redundant check in those cases (since the address
would be validated at time of lookup()
there).
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.
LGTM % moving the check
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.
Error messages need assertion
lib/internal/errors.js
Outdated
@@ -182,7 +182,8 @@ E('ERR_V8BREAKITERATOR', 'full ICU data not installed. ' + | |||
function invalidArgType(name, expected, actual) { | |||
const assert = lazyAssert(); | |||
assert(name, 'name is required'); | |||
var msg = `The "${name}" argument must be ${oneOf(expected, 'type')}`; | |||
const type = name.includes('.') ? 'property' : 'argument' |
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.
This makes this a semver-major
. Is it worth it?
{ | ||
assert.throws(() => { | ||
net.createConnection({ path: {} }); | ||
}, TypeError); |
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.
Re: asserting error messages, Could you use expectsError
})); | ||
c.on('connect', common.mustNotCall()); | ||
c.on('error', common.mustCall(function(e) { | ||
assert.strictEqual(e.code, 'ENOENT'); |
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.
expectsError
ditto
3 tests fail 917 parallel/test-process-cpuUsage
duration_ms 0.58
severity fail
stack |-
assert.js:60
throw new errors.AssertionError({
^
AssertionError [ERR_ASSERTION]: 'The "preValue.user" property must be of type Number' === 'The "preValue.user" argument must be of type Number'
at Object.<anonymous> (/data/iojs/build/workspace/node-test-commit-linuxone/nodes/rhel72-s390x/test/common/index.js:703:14)
at expectedException (assert.js:520:19)
at _throws (assert.js:568:8)
at Function.throws (assert.js:577:3)
at Object.<anonymous> (/data/iojs/build/workspace/node-test-commit-linuxone/nodes/rhel72-s390x/test/parallel/test-process-cpuUsage.js:48:8)
at Module._compile (module.js:569:30)
at Object.Module._extensions..js (module.js:580:10)
at Module.load (module.js:503:32)
at tryModuleLoad (module.js:466:12)
at Function.Module._load (module.js:458:3) |
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.
LGTM as a semver patch with the comment addressed.
I see 3 CTC approvals, but still think it would be nice to have this as |
There's no -0.1 from me at all. I marked it as a semver-major because of our policy, but I'm fine with it being a patch as long as there is consensus for doing so. |
Cool! I see consensus. |
PR-URL: nodejs#13726 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
Landed in f40caf7 |
Quick extra sanity: https://ci.nodejs.org/job/node-test-commit-linuxone/6756/ ✔️ |
PR-URL: #13726 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
PR-URL: #13726 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
This does not land cleanly in LTS. Please feel free to manually backport. Please also feel free to replace the backport request label with do-not-land if it shouldn't land |
PR-URL: nodejs#13726 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
I opened a PR with a backport for 6.x |
Calling
net.createConnection
with a bad path results in a segfault. This fixes this by checking for the type and by throwing a TypeError in case it's not a string.Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passesAffected core subsystem(s)
net