From da1ee44ac69c580cedf7c5d86142f9181a5bad01 Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Wed, 11 Aug 2021 12:53:34 +0200 Subject: [PATCH 1/2] src: fix crash in AfterGetAddrInfo 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 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] --- src/cares_wrap.cc | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/cares_wrap.cc b/src/cares_wrap.cc index 9372aa6b7cc3bf..a91830cb27f137 100644 --- a/src/cares_wrap.cc +++ b/src/cares_wrap.cc @@ -63,7 +63,10 @@ using v8::HandleScope; using v8::Int32; using v8::Integer; using v8::Isolate; +using v8::Just; +using v8::Maybe; using v8::Local; +using v8::Nothing; using v8::Null; using v8::Object; using v8::String; @@ -1443,7 +1446,7 @@ void AfterGetAddrInfo(uv_getaddrinfo_t* req, int status, struct addrinfo* res) { if (status == 0) { Local results = Array::New(env->isolate()); - auto add = [&] (bool want_ipv4, bool want_ipv6) { + auto add = [&] (bool want_ipv4, bool want_ipv6) -> Maybe { for (auto p = res; p != nullptr; p = p->ai_next) { CHECK_EQ(p->ai_socktype, SOCK_STREAM); @@ -1463,14 +1466,19 @@ void AfterGetAddrInfo(uv_getaddrinfo_t* req, int status, struct addrinfo* res) { continue; Local s = OneByteString(env->isolate(), ip); - results->Set(env->context(), n, s).Check(); + if (results->Set(env->context(), n, s).IsNothing()) + return Nothing(); 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) { From 698000be439f2cde478e32922a4903986fdc58cf Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Wed, 11 Aug 2021 13:02:26 +0200 Subject: [PATCH 2/2] fixup: lint --- src/cares_wrap.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cares_wrap.cc b/src/cares_wrap.cc index a91830cb27f137..edc86761876224 100644 --- a/src/cares_wrap.cc +++ b/src/cares_wrap.cc @@ -64,8 +64,8 @@ using v8::Int32; using v8::Integer; using v8::Isolate; using v8::Just; -using v8::Maybe; using v8::Local; +using v8::Maybe; using v8::Nothing; using v8::Null; using v8::Object;