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: prevent crash in TTYWrap::Initialize #26832

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions src/tty_wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ namespace node {

using v8::Array;
using v8::Context;
using v8::Function;
using v8::FunctionCallbackInfo;
using v8::FunctionTemplate;
using v8::Integer;
Expand All @@ -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,
Expand All @@ -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);
}
}


Expand Down
20 changes: 20 additions & 0 deletions test/parallel/test-ttywrap-stack.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
'use strict';
const common = require('../common');

// This test ensures that console.log
// will not crash the process if there
// is not enough space on the V8 stack

const done = common.mustCall(() => {});
joyeecheung marked this conversation as resolved.
Show resolved Hide resolved

async function test() {
await test();
}

(async () => {
try {
await test();
} catch (err) {
console.log(err);
}
})().then(done, done);