summaryrefslogtreecommitdiff
path: root/src/node_object_wrap.h
diff options
context:
space:
mode:
authorBen Noordhuis <info@bnoordhuis.nl>2013-09-06 20:59:27 +0200
committerBen Noordhuis <info@bnoordhuis.nl>2013-09-06 21:19:55 +0200
commitb89b97ddedc5b659e5592917d4789a31723ceca3 (patch)
treefc69b629256d56db417a547b4f7909a12ef46bca /src/node_object_wrap.h
parent756b6222956b5d25b2e7db81f4e79033a3a4d20e (diff)
downloadandroid-node-v8-b89b97ddedc5b659e5592917d4789a31723ceca3.tar.gz
android-node-v8-b89b97ddedc5b659e5592917d4789a31723ceca3.tar.bz2
android-node-v8-b89b97ddedc5b659e5592917d4789a31723ceca3.zip
src: fix multi-base class ObjectWrap::Unwrap<T>()
Fix pointer unwrapping when T is a class with more than one base class. Before this commit, the wrapped void* pointer was cast directly to T* without going through ObjectWrap* first, possibly leading to a class instance pointer that points to the wrong vtable. This change required some cleanup in various files; some classes used private rather than public inheritance, others didn't derive from ObjectWrap at all... Fixes #6188.
Diffstat (limited to 'src/node_object_wrap.h')
-rw-r--r--src/node_object_wrap.h6
1 files changed, 5 insertions, 1 deletions
diff --git a/src/node_object_wrap.h b/src/node_object_wrap.h
index 5c6ab2865b..683123559f 100644
--- a/src/node_object_wrap.h
+++ b/src/node_object_wrap.h
@@ -56,7 +56,11 @@ class NODE_EXTERN ObjectWrap {
static inline T* Unwrap(v8::Handle<v8::Object> handle) {
assert(!handle.IsEmpty());
assert(handle->InternalFieldCount() > 0);
- return static_cast<T*>(handle->GetAlignedPointerFromInternalField(0));
+ // Cast to ObjectWrap before casting to T. A direct cast from void
+ // to T won't work right when T has more than one base class.
+ void* ptr = handle->GetAlignedPointerFromInternalField(0);
+ ObjectWrap* wrap = static_cast<ObjectWrap*>(ptr);
+ return static_cast<T*>(wrap);
}