diff options
author | Anna Henningsen <anna@addaleax.net> | 2018-06-07 14:43:45 +0200 |
---|---|---|
committer | Anna Henningsen <anna@addaleax.net> | 2018-06-14 00:43:45 +0200 |
commit | 22c826f5aa3811e758686fd00a8fe15728f6fc37 (patch) | |
tree | 1cf89936945abb32e76fc779a55c03dab341e9fb /src/async_wrap-inl.h | |
parent | 61e9e3c26b3730f10b5c4d90af68e76eed35d3e6 (diff) | |
download | node-new-22c826f5aa3811e758686fd00a8fe15728f6fc37.tar.gz |
src: do proper error checking in `AsyncWrap::MakeCallback`
At least one method on a native object is added as a getter,
namely `MessagePort.prototype.onmessage`. When a MessagePort
attempts to call this method from C++ in response to receiving
data, it will first invoke that getter and then call the function.
Since `worker.terminate()` interrupts execution, this means
that the getter may fail (without being faulty code on its own).
This means that at least one test exercising these methods in
combination has been flaky and could have crashed, because
we did not actually check that the getter returns a value
so far, resulting in dereferencing an empty `Local`.
The proper fix for this is to use the non-deprecated overload
of `Get()` and check the result like we should be doing.
Also, as a (related) fix, don’t crash if the method
is not a function but rather something else, like a getter
could provide.
Example test failure: https://ci.nodejs.org/job/node-test-commit-linux-containered/4976/nodes=ubuntu1604_sharedlibs_zlib_x64/console
17:56:56 not ok 1955 parallel/test-worker-dns-terminate
17:56:56 ---
17:56:56 duration_ms: 1.237
17:56:56 severity: crashed
17:56:56 exitcode: -11
17:56:56 stack: |-
PR-URL: https://github.com/nodejs/node/pull/21189
Reviewed-By: Anatoli Papirovski <apapirovski@mac.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'src/async_wrap-inl.h')
-rw-r--r-- | src/async_wrap-inl.h | 20 |
1 files changed, 8 insertions, 12 deletions
diff --git a/src/async_wrap-inl.h b/src/async_wrap-inl.h index 5763b17aa0..4405bb3a9b 100644 --- a/src/async_wrap-inl.h +++ b/src/async_wrap-inl.h @@ -81,18 +81,14 @@ inline v8::MaybeLocal<v8::Value> AsyncWrap::MakeCallback( const v8::Local<v8::Name> symbol, int argc, v8::Local<v8::Value>* argv) { - v8::Local<v8::Value> cb_v = object()->Get(symbol); - CHECK(cb_v->IsFunction()); - return MakeCallback(cb_v.As<v8::Function>(), argc, argv); -} - - -inline v8::MaybeLocal<v8::Value> AsyncWrap::MakeCallback( - uint32_t index, - int argc, - v8::Local<v8::Value>* argv) { - v8::Local<v8::Value> cb_v = object()->Get(index); - CHECK(cb_v->IsFunction()); + v8::Local<v8::Value> cb_v; + if (!object()->Get(env()->context(), symbol).ToLocal(&cb_v)) + return v8::MaybeLocal<v8::Value>(); + if (!cb_v->IsFunction()) { + // TODO(addaleax): We should throw an error here to fulfill the + // `MaybeLocal<>` API contract. + return v8::MaybeLocal<v8::Value>(); + } return MakeCallback(cb_v.As<v8::Function>(), argc, argv); } |