diff options
author | Trevor Norris <trev.norris@gmail.com> | 2016-04-13 13:16:42 -0600 |
---|---|---|
committer | Trevor Norris <trev.norris@gmail.com> | 2016-05-24 14:40:22 -0600 |
commit | c0e6c668e6e6f0ba6a924a5b83ff1ca5434d14ad (patch) | |
tree | 2f24e1329abb6b5432273246b4754ec44e7b3e8a /src/stream_base-inl.h | |
parent | 13e5d4f32014e3426142580a699d0ffdf02db26a (diff) | |
download | android-node-v8-c0e6c668e6e6f0ba6a924a5b83ff1ca5434d14ad.tar.gz android-node-v8-c0e6c668e6e6f0ba6a924a5b83ff1ca5434d14ad.tar.bz2 android-node-v8-c0e6c668e6e6f0ba6a924a5b83ff1ca5434d14ad.zip |
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 <info@bnoordhuis.nl>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Diffstat (limited to 'src/stream_base-inl.h')
-rw-r--r-- | src/stream_base-inl.h | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/src/stream_base-inl.h b/src/stream_base-inl.h index e8e73f007e..bdc8211707 100644 --- a/src/stream_base-inl.h +++ b/src/stream_base-inl.h @@ -80,8 +80,9 @@ void StreamBase::GetFD(Local<String> key, Base* handle = Unwrap<Base>(args.Holder()); // Mimic implementation of StreamBase::GetFD() and UDPWrap::GetFD(). - if (handle == nullptr) - return args.GetReturnValue().Set(-1); + ASSIGN_OR_RETURN_UNWRAP(&handle, + args.Holder(), + args.GetReturnValue().Set(UV_EINVAL)); StreamBase* wrap = static_cast<StreamBase*>(handle); if (!wrap->IsAlive()) @@ -97,8 +98,9 @@ void StreamBase::GetBytesRead(Local<String> key, Base* handle = Unwrap<Base>(args.Holder()); // The handle instance hasn't been set. So no bytes could have been read. - if (handle == nullptr) - return args.GetReturnValue().Set(0); + ASSIGN_OR_RETURN_UNWRAP(&handle, + args.Holder(), + args.GetReturnValue().Set(0)); StreamBase* wrap = static_cast<StreamBase*>(handle); // uint64_t -> double. 53bits is enough for all real cases. @@ -111,8 +113,7 @@ void StreamBase::GetExternal(Local<String> key, const PropertyCallbackInfo<Value>& args) { Base* handle = Unwrap<Base>(args.Holder()); - if (handle == nullptr) - return args.GetReturnValue().SetUndefined(); + ASSIGN_OR_RETURN_UNWRAP(&handle, args.Holder()); StreamBase* wrap = static_cast<StreamBase*>(handle); Local<External> ext = External::New(args.GetIsolate(), wrap); @@ -125,8 +126,7 @@ template <class Base, void StreamBase::JSMethod(const FunctionCallbackInfo<Value>& args) { Base* handle = Unwrap<Base>(args.Holder()); - if (handle == nullptr) - return args.GetReturnValue().SetUndefined(); + ASSIGN_OR_RETURN_UNWRAP(&handle, args.Holder()); StreamBase* wrap = static_cast<StreamBase*>(handle); if (!wrap->IsAlive()) |