diff options
author | Thomas <hakerh403@gmail.com> | 2019-03-21 04:01:19 +0300 |
---|---|---|
committer | Ruben Bridgewater <ruben@bridgewater.de> | 2019-04-04 16:35:02 +0300 |
commit | 6fb32ac2552a0a03b8e7d54ef9bda06909823b6b (patch) | |
tree | 8b9523d5913c8474e45efa56f6531352fcc929b7 /src/tty_wrap.cc | |
parent | b965ac22ca81a449c9e88f066cadcb8abf93f94b (diff) |
src: prevent crash in TTYWrap::Initialize
When console.log is called for the first time it initializes
TTYWrap object. However, if there is not enough space on the
V8 stack, creating function template fails and triggers
empty maybe local exception.
PR-URL: https://github.com/nodejs/node/pull/26832
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Diffstat (limited to 'src/tty_wrap.cc')
-rw-r--r-- | src/tty_wrap.cc | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/src/tty_wrap.cc b/src/tty_wrap.cc index 405b70343f7..33dd4dbdacf 100644 --- a/src/tty_wrap.cc +++ b/src/tty_wrap.cc @@ -32,6 +32,7 @@ namespace node { using v8::Array; using v8::Context; +using v8::Function; using v8::FunctionCallbackInfo; using v8::FunctionTemplate; using v8::Integer; @@ -40,7 +41,6 @@ using v8::Object; using v8::String; using v8::Value; - void TTYWrap::Initialize(Local<Object> target, Local<Value> unused, Local<Context> context, @@ -61,10 +61,11 @@ void TTYWrap::Initialize(Local<Object> target, env->SetMethodNoSideEffect(target, "isTTY", IsTTY); env->SetMethodNoSideEffect(target, "guessHandleType", GuessHandleType); - target->Set(env->context(), - ttyString, - t->GetFunction(env->context()).ToLocalChecked()).FromJust(); - env->set_tty_constructor_template(t); + Local<Value> func; + if (t->GetFunction(env->context()).ToLocal(&func) && + target->Set(env->context(), ttyString, func).IsJust()) { + env->set_tty_constructor_template(t); + } } |