Skip to content

Commit 6076293

Browse files
trevnorrisMylesBorins
authored andcommitted
tls_wrap: do not abort on new TLSWrap()
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 <[email protected]> Reviewed-By: Anna Henningsen <[email protected]>
1 parent 166a9b8 commit 6076293

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

src/tls_wrap.cc

+4-1
Original file line numberDiff line numberDiff line change
@@ -888,7 +888,10 @@ void TLSWrap::Initialize(Local<Object> target,
888888

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

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

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
'use strict';
2+
3+
require('../common');
4+
const util = require('util');
5+
const TLSWrap = process.binding('tls_wrap').TLSWrap;
6+
7+
// This will abort if internal pointer is not set to nullptr.
8+
util.inspect(new TLSWrap());

0 commit comments

Comments
 (0)