-
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
dns: fix crash while using dns.setServers after dns.resolve4 #13050
dns: fix crash while using dns.setServers after dns.resolve4 #13050
Conversation
The related cares code is under ares_process.c. query->callback(query->arg, status, query->timeouts, abuf, alen);
ares__free_query(query); If real callback is synchronous and we do |
79cd9b4
to
279c383
Compare
279c383
to
9806008
Compare
Awesome! Someone else will have to comment on the C++ code. /cc @trevnorris @indutny @addaleax @danbev But I can comment on the test. The test itself looks good. Some small comments:
/cc @nodejs/testing |
Thanks for your suggestions. |
Are you sure about that? If I change your test code to this: 'use strict';
const common = require('../common');
const dns = require('dns');
dns.resolve4('nodejs.org', common.mustCall(function(err, nameServers) {
if (err)
throw err;
})); ...running it with a network connection results in no error. If I run it without a network connection enabled, I get |
I see. Actually I don't care about whether it will throw an error or not. My test destination is to test whether the case will crash or not. Anyway, I moved the test case under internet now. Before this fixture PR, that test case will fail because of crash. |
Shouldn't this target |
@silverwind hmmmm, I think if this PR is merged, we can port it to master. But if reviewers consider that this PR must target to |
We generally land on master first and then backport it after a few weeks/months, so I'd appreciate if you target master now. |
The callback function in cares_query is synchronous and called before closed. So dns.setServers in the synchronous callback before closed will occur crashing. Fixes: nodejs#894 Refs: https://github.com/nodejs/node/blob/v6.9.4/deps/cares/src/ares_process.c#L1332-L1333 Refs: https://github.com/OpenSIPS/opensips/blob/2.3.0/proxy.c
eeb7813
to
0c51d0a
Compare
@silverwind I've updated the PR to make |
I can confirm it fixes the test case in #894. |
Excellent work! Thanks for the patch. To my understanding this PR simply postponed the execution of the callback of |
My consideration is that: If we solve this bug in JavaScript level, the bug will still exist if developers use DNS binding directly. @pmq20 Or if someone add some new features for |
src/cares_wrap.cc
Outdated
@@ -296,6 +300,121 @@ Local<Array> HostentToNames(Environment* env, struct hostent* host) { | |||
return scope.Escape(names); | |||
} | |||
|
|||
/* copies a hostent structure*, returns 0 on success, -1 on error */ | |||
/* this function refers to OpenSIPS */ |
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 is code that was licensed under the GPL, we can’t use it – sorry.
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.
Okay, I'll rewrite this function then.
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.
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.
Thx. I've rewritten those two functions by myself now.
Landed in 5a948f6, thanks for the PR! |
The callback function in cares_query is synchronous and called before closed. So dns.setServers in the synchronous callback before closed will occur crashing. Fixes: #894 Refs: https://github.com/nodejs/node/blob/v6.9.4/deps/cares/src/ares_process.c#L1332-L1333 Refs: https://github.com/OpenSIPS/opensips/blob/2.3.0/proxy.c PR-URL: #13050 Reviewed-By: Anna Henningsen <anna@addaleax.net>
@XadillaX congrats 🎉 is this your first code contribution? |
It is. Pretty awesome first contribution! |
Yes, it is my first contribution. Thank you all for helping with my first contribution! |
The callback function in cares_query is synchronous and called before closed. So dns.setServers in the synchronous callback before closed will occur crashing. Fixes: nodejs#894 Refs: https://github.com/nodejs/node/blob/v6.9.4/deps/cares/src/ares_process.c#L1332-L1333 Refs: https://github.com/OpenSIPS/opensips/blob/2.3.0/proxy.c PR-URL: nodejs#13050 Reviewed-By: Anna Henningsen <anna@addaleax.net>
|
This commit fixes two coverity warnings for unchecked return values. Refs: nodejs#13050 PR-URL: nodejs#13116 Reviewed-By: Sam Roberts <vieuxtech@gmail.com> Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com> Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com>
This commit fixes two coverity warnings for unchecked return values. Refs: #13050 PR-URL: #13116 Reviewed-By: Sam Roberts <vieuxtech@gmail.com> Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com> Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com>
This commit fixes two coverity warnings for unchecked return values. Refs: #13050 PR-URL: #13116 Reviewed-By: Sam Roberts <vieuxtech@gmail.com> Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com> Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com>
The callback function in cares_query is synchronous and called before closed. So dns.setServers in the synchronous callback before closed will occur crashing. Fixes: nodejs#894 Refs: https://github.com/nodejs/node/blob/v6.9.4/deps/cares/src/ares_process.c#L1332-L1333 Refs: https://github.com/OpenSIPS/opensips/blob/2.3.0/proxy.c PR-URL: nodejs#13050 Reviewed-By: Anna Henningsen <anna@addaleax.net>
It would appear that this is causing build errors on v6.x. I have labelled it as If it does land it needs to come with 06f62eb edit: I left dont land off for now until we hear that someone can say if this needs to land |
The callback function in cares_query is synchronous and called before closed. So dns.setServers in the synchronous callback before closed will occur crashing. Fixes: #894 Refs: https://github.com/nodejs/node/blob/v6.9.4/deps/cares/src/ares_process.c#L1332-L1333 Refs: https://github.com/OpenSIPS/opensips/blob/2.3.0/proxy.c Backport-PR-URL: #13724 PR-URL: #13050 Reviewed-By: Anna Henningsen <anna@addaleax.net>
This commit fixes two coverity warnings for unchecked return values. Refs: #13050 PR-URL: #13116 Reviewed-By: Sam Roberts <vieuxtech@gmail.com> Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com> Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com>
The callback function in cares_query is synchronous and called before closed. So dns.setServers in the synchronous callback before closed will occur crashing. Fixes: #894 Refs: https://github.com/nodejs/node/blob/v6.9.4/deps/cares/src/ares_process.c#L1332-L1333 Refs: https://github.com/OpenSIPS/opensips/blob/2.3.0/proxy.c Backport-PR-URL: #13724 PR-URL: #13050 Reviewed-By: Anna Henningsen <anna@addaleax.net>
This commit fixes two coverity warnings for unchecked return values. Refs: #13050 PR-URL: #13116 Reviewed-By: Sam Roberts <vieuxtech@gmail.com> Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com> Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com>
The callback function in
cares_query
is synchronous and called before closed. Sodns.setServers
in the synchronous callback before closed will occur crashing.This PR makes the real callback of
dns.resolve4
or some other functions indns
asynchronous to resolve this problem.Solution
I use
uv_async_t
to send thecallback
task to next loop. And the task data is created fromCaresAsyncData
.Because
Callback
has two functions with parametershostent*
orunsigned char*, int
,CaresAsyncData
has a flagis_host
to distinguish them.In the
Callback
function, whetherhostent*
orunsigned char*
will be destroyed after this function is done. So I make a copy for those buffers for asynchronous use. In the asynchronous function and asynchronous done callback, I delete some related pointers.Related Issue: #894 #1071
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passesAffected core subsystem(s)
dns