From 57f38c6732db71a6145cc5bbfec884f47bb17e16 Mon Sep 17 00:00:00 2001 From: Daniel Bevenius Date: Thu, 18 May 2017 10:24:50 +0200 Subject: [PATCH] src: check IsConstructCall in TLSWrap constructor Currently it is possible to call TLSWrap() without using new and the following error message: FATAL ERROR: v8::Object::SetAlignedPointerInInternalField() Internal field out of bounds 1: node::Abort() [/Users/danielbevenius/work/nodejs/node/out/Debug/node] 2: node::OnFatalError(char const*, char const*) [/Users/danielbevenius/work/nodejs/node/out/Debug/node] 3: v8::Utils::ReportApiFailure(char const*, char const*) [/Users/danielbevenius/work/nodejs/node/out/Debug/node] 4: v8::Utils::ApiCheck(bool, char const*, char const*) [/Users/danielbevenius/work/nodejs/node/out/Debug/node] 5: v8::InternalFieldOK(v8::internal::Handle, int, char const*) [/Users/danielbevenius/work/nodejs/node/out/Debug/node] 6: v8::Object::SetAlignedPointerInInternalField(int, void*) [/Users/danielbevenius/work/nodejs/node/out/Debug/node] 7: node::TLSWrap::Initialize(v8::Local, v8::Local, v8::Local)::$_0::operator()(v8::FunctionCallbackInfo const&) const [/Users/danielbevenius/work/nodejs/node/out/Debug/node] This commit adds a IsConstructCall check which will produce the following error message: /Users/danielbevenius/work/nodejs/node/out/Debug/node[2212]: ../src/tls_wrap.cc:936:auto node::TLSWrap::Initialize(Local, Local, Local)::(anonymous class)::operator()(const FunctionCallbackInfo &) const: Assertion `args.IsConstructCall()' failed. 1: node::Abort() [/Users/danielbevenius/work/nodejs/node/out/Debug/node] 2: node::Assert(char const* const (*) [4]) [/Users/danielbevenius/work/nodejs/node/out/Debug/node] 3: node::TLSWrap::Initialize(v8::Local, v8::Local, v8::Local)::$_0::operator()(v8::FunctionCallbackInfo const&) const [/Users/danielbevenius/work/nodejs/node/out/Debug/node] PR-URL: https://github.com/nodejs/node/pull/13097 Reviewed-By: Ben Noordhuis Reviewed-By: Anna Henningsen Reviewed-By: Colin Ihrig --- src/tls_wrap.cc | 1 + 1 file changed, 1 insertion(+) diff --git a/src/tls_wrap.cc b/src/tls_wrap.cc index e6de9423710706..351f8a34fe0884 100644 --- a/src/tls_wrap.cc +++ b/src/tls_wrap.cc @@ -933,6 +933,7 @@ void TLSWrap::Initialize(Local target, env->SetMethod(target, "wrap", TLSWrap::Wrap); auto constructor = [](const FunctionCallbackInfo& args) { + CHECK(args.IsConstructCall()); args.This()->SetAlignedPointerInInternalField(0, nullptr); }; auto t = env->NewFunctionTemplate(constructor);