From b89b97ddedc5b659e5592917d4789a31723ceca3 Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Fri, 6 Sep 2013 20:59:27 +0200 Subject: src: fix multi-base class ObjectWrap::Unwrap() 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. --- src/node_object_wrap.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'src/node_object_wrap.h') 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 handle) { assert(!handle.IsEmpty()); assert(handle->InternalFieldCount() > 0); - return static_cast(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(ptr); + return static_cast(wrap); } -- cgit v1.2.3