Skip to content

Commit

Permalink
src: fix crash in AfterGetAddrInfo
Browse files Browse the repository at this point in the history
Remove invalid usage of `Check()`. This addresses:

    FATAL ERROR: v8::FromJust Maybe value is Nothing.
     1: 0x101311bf5 node::Abort() (.cold.1) [/Users/xxx/.nvm/versions/node/v14.17.4/bin/node]
     2: 0x1000ade29 node::Abort() [/Users/xxx/.nvm/versions/node/v14.17.4/bin/node]
     3: 0x1000adf8f node::OnFatalError(char const*, char const*) [/Users/xxx/.nvm/versions/node/v14.17.4/bin/node]
     4: 0x1001f42d0 v8::V8::FromJustIsNothing() [/Users/xxx/.nvm/versions/node/v14.17.4/bin/node]
     5: 0x1000268e2 node::cares_wrap::(anonymous namespace)::AfterGetAddrInfo(uv_getaddrinfo_s*, int, addrinfo*)::$_2::operator()(bool, bool) const [/Users/xxx/.nvm/versions/node/v14.17.4/bin/node]
     6: 0x10002657c node::cares_wrap::(anonymous namespace)::AfterGetAddrInfo(uv_getaddrinfo_s*, int, addrinfo*) [/Users/xxx/.nvm/versions/node/v14.17.4/bin/node]
     7: 0x1009fb388 uv__work_done [/Users/xxx/.nvm/versions/node/v14.17.4/bin/node]
     8: 0x100a00453 uv__async_io [/Users/xxx/.nvm/versions/node/v14.17.4/bin/node]
     9: 0x100a140cc uv__io_poll [/Users/xxx/.nvm/versions/node/v14.17.4/bin/node]
    10: 0x100a009c1 uv_run [/Users/xxx/.nvm/versions/node/v14.17.4/bin/node]
    11: 0x10014aca0 node::worker::Worker::Run() [/Users/xxx/.nvm/versions/node/v14.17.4/bin/node]
    12: 0x10014e56f node::worker::Worker::StartThread(v8::FunctionCallbackInfo<v8::Value> const&)::$_3::__invoke(void*) [/Users/xxx/.nvm/versions/node/v14.17.4/bin/node]
    13: 0x7fff703d42eb _pthread_body [/usr/lib/system/libsystem_pthread.dylib]
    14: 0x7fff703d7249 _pthread_start [/usr/lib/system/libsystem_pthread.dylib]
    15: 0x7fff703d340d thread_start [/usr/lib/system/libsystem_pthread.dylib]

PR-URL: #39735
Reviewed-By: Michaël Zasso <[email protected]>
Reviewed-By: Tobias Nießen <[email protected]>
Reviewed-By: James M Snell <[email protected]>
  • Loading branch information
addaleax authored and targos committed Sep 4, 2021
1 parent 5459f4a commit 02b1df9
Showing 1 changed file with 13 additions and 5 deletions.
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

0 comments on commit 02b1df9

Please sign in to comment.