Skip to content
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

src: fix crash in AfterGetAddrInfo #39735

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 13 additions & 5 deletions src/cares_wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,10 @@ using v8::HandleScope;
using v8::Int32;
using v8::Integer;
using v8::Isolate;
using v8::Just;
using v8::Local;
using v8::Maybe;
using v8::Nothing;
using v8::Null;
using v8::Object;
using v8::String;
Expand Down Expand Up @@ -1443,7 +1446,7 @@ void AfterGetAddrInfo(uv_getaddrinfo_t* req, int status, struct addrinfo* res) {
if (status == 0) {
Local<Array> results = Array::New(env->isolate());

auto add = [&] (bool want_ipv4, bool want_ipv6) {
auto add = [&] (bool want_ipv4, bool want_ipv6) -> Maybe<bool> {
for (auto p = res; p != nullptr; p = p->ai_next) {
CHECK_EQ(p->ai_socktype, SOCK_STREAM);

Expand All @@ -1463,14 +1466,19 @@ void AfterGetAddrInfo(uv_getaddrinfo_t* req, int status, struct addrinfo* res) {
continue;

Local<String> s = OneByteString(env->isolate(), ip);
results->Set(env->context(), n, s).Check();
if (results->Set(env->context(), n, s).IsNothing())
return Nothing<bool>();
n++;
}
return Just(true);
};

add(true, verbatim);
if (verbatim == false)
add(false, true);
if (add(true, verbatim).IsNothing())
return;
if (verbatim == false) {
if (add(false, true).IsNothing())
return;
}

// No responses were found to return
if (n == 0) {
Expand Down