From c0e6c668e6e6f0ba6a924a5b83ff1ca5434d14ad Mon Sep 17 00:00:00 2001 From: Trevor Norris Date: Wed, 13 Apr 2016 13:16:42 -0600 Subject: src: no abort from getter if object isn't wrapped v8::Object::GetAlignedPointerFromInternalField() returns a random value if Wrap() hasn't been run on the object handle. Causing v8 to abort if certain getters are accessed. It's possible to access these getters and functions during class construction through the AsyncWrap init() callback, and also possible in a subset of those scenarios while running the persistent handle visitor. Mitigate this issue by manually setting the internal aligned pointer field to nullptr in the BaseObject constructor and add necessary logic to return appropriate values when nullptr is encountered. PR-URL: https://github.com/nodejs/node/pull/6184 Reviewed-By: Ben Noordhuis Reviewed-By: Anna Henningsen --- src/pipe_wrap.cc | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) (limited to 'src/pipe_wrap.cc') diff --git a/src/pipe_wrap.cc b/src/pipe_wrap.cc index 7be07de74b..286ea30a87 100644 --- a/src/pipe_wrap.cc +++ b/src/pipe_wrap.cc @@ -138,7 +138,8 @@ PipeWrap::PipeWrap(Environment* env, void PipeWrap::Bind(const FunctionCallbackInfo& args) { - PipeWrap* wrap = Unwrap(args.Holder()); + PipeWrap* wrap; + ASSIGN_OR_RETURN_UNWRAP(&wrap, args.Holder()); node::Utf8Value name(args.GetIsolate(), args[0]); int err = uv_pipe_bind(&wrap->handle_, *name); args.GetReturnValue().Set(err); @@ -147,7 +148,8 @@ void PipeWrap::Bind(const FunctionCallbackInfo& args) { #ifdef _WIN32 void PipeWrap::SetPendingInstances(const FunctionCallbackInfo& args) { - PipeWrap* wrap = Unwrap(args.Holder()); + PipeWrap* wrap; + ASSIGN_OR_RETURN_UNWRAP(&wrap, args.Holder()); int instances = args[0]->Int32Value(); uv_pipe_pending_instances(&wrap->handle_, instances); } @@ -155,7 +157,8 @@ void PipeWrap::SetPendingInstances(const FunctionCallbackInfo& args) { void PipeWrap::Listen(const FunctionCallbackInfo& args) { - PipeWrap* wrap = Unwrap(args.Holder()); + PipeWrap* wrap; + ASSIGN_OR_RETURN_UNWRAP(&wrap, args.Holder()); int backlog = args[0]->Int32Value(); int err = uv_listen(reinterpret_cast(&wrap->handle_), backlog, @@ -191,7 +194,8 @@ void PipeWrap::OnConnection(uv_stream_t* handle, int status) { Local client_obj = Instantiate(env, pipe_wrap); // Unwrap the client javascript object. - PipeWrap* wrap = Unwrap(client_obj); + PipeWrap* wrap; + ASSIGN_OR_RETURN_UNWRAP(&wrap, client_obj); uv_stream_t* client_handle = reinterpret_cast(&wrap->handle_); if (uv_accept(handle, client_handle)) return; @@ -242,7 +246,8 @@ void PipeWrap::AfterConnect(uv_connect_t* req, int status) { void PipeWrap::Open(const FunctionCallbackInfo& args) { Environment* env = Environment::GetCurrent(args); - PipeWrap* wrap = Unwrap(args.Holder()); + PipeWrap* wrap; + ASSIGN_OR_RETURN_UNWRAP(&wrap, args.Holder()); int fd = args[0]->Int32Value(); @@ -256,7 +261,8 @@ void PipeWrap::Open(const FunctionCallbackInfo& args) { void PipeWrap::Connect(const FunctionCallbackInfo& args) { Environment* env = Environment::GetCurrent(args); - PipeWrap* wrap = Unwrap(args.Holder()); + PipeWrap* wrap; + ASSIGN_OR_RETURN_UNWRAP(&wrap, args.Holder()); CHECK(args[0]->IsObject()); CHECK(args[1]->IsString()); -- cgit v1.2.3