Skip to content

Commit

Permalink
tls_wrap: do not abort on new TLSWrap()
Browse files Browse the repository at this point in the history
Though the TLSWrap constructor is only called via TLSWrap::Wrap() (i.e.
tls_wrap.wrap()) internally, it is still exposed to JS. Don't allow the
application to abort by inspecting the instance before it has been
wrap'd by another handle.

PR-URL: #6184
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
  • Loading branch information
trevnorris authored and rvagg committed Jun 2, 2016
1 parent 4da3e1e commit 5779ed2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/tls_wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -888,7 +888,10 @@ void TLSWrap::Initialize(Local<Object> target,

env->SetMethod(target, "wrap", TLSWrap::Wrap);

Local<FunctionTemplate> t = FunctionTemplate::New(env->isolate());
auto constructor = [](const FunctionCallbackInfo<Value>& args) {
args.This()->SetAlignedPointerInInternalField(0, nullptr);
};
auto t = env->NewFunctionTemplate(constructor);
t->InstanceTemplate()->SetInternalFieldCount(1);
t->SetClassName(FIXED_ONE_BYTE_STRING(env->isolate(), "TLSWrap"));

Expand Down
8 changes: 8 additions & 0 deletions test/parallel/test-tls-wrap-no-abort.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
'use strict';

require('../common');
const util = require('util');
const TLSWrap = process.binding('tls_wrap').TLSWrap;

// This will abort if internal pointer is not set to nullptr.
util.inspect(new TLSWrap());

0 comments on commit 5779ed2

Please sign in to comment.