From 5779ed2a4a14b7cebb75362f537bf252703095c3 Mon Sep 17 00:00:00 2001 From: Trevor Norris Date: Sat, 16 Apr 2016 03:17:54 -0600 Subject: [PATCH] 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: https://github.com/nodejs/node/pull/6184 Reviewed-By: Ben Noordhuis Reviewed-By: Anna Henningsen --- src/tls_wrap.cc | 5 ++++- test/parallel/test-tls-wrap-no-abort.js | 8 ++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 test/parallel/test-tls-wrap-no-abort.js diff --git a/src/tls_wrap.cc b/src/tls_wrap.cc index d4214ed7c3..779587fe36 100644 --- a/src/tls_wrap.cc +++ b/src/tls_wrap.cc @@ -888,7 +888,10 @@ void TLSWrap::Initialize(Local target, env->SetMethod(target, "wrap", TLSWrap::Wrap); - Local t = FunctionTemplate::New(env->isolate()); + auto constructor = [](const FunctionCallbackInfo& args) { + args.This()->SetAlignedPointerInInternalField(0, nullptr); + }; + auto t = env->NewFunctionTemplate(constructor); t->InstanceTemplate()->SetInternalFieldCount(1); t->SetClassName(FIXED_ONE_BYTE_STRING(env->isolate(), "TLSWrap")); diff --git a/test/parallel/test-tls-wrap-no-abort.js b/test/parallel/test-tls-wrap-no-abort.js new file mode 100644 index 0000000000..a64aea0b05 --- /dev/null +++ b/test/parallel/test-tls-wrap-no-abort.js @@ -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());