Skip to content

Commit cfa597c

Browse files
sync: from linuxdeepin/qt5platform-plugins
Synchronize source files from linuxdeepin/qt5platform-plugins. Source-pull-request: linuxdeepin/qt5platform-plugins#305
1 parent 22347c1 commit cfa597c

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

src/vtablehook.cpp

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -238,12 +238,33 @@ bool VtableHook::ensureVtable(const void *obj, std::function<void ()> destoryObj
238238
* \brief VtableHook::hasVtable 对象的虚表已经被覆盖时返回true,否则返回false
239239
* \param obj
240240
* \return
241+
*
242+
* 修复: 不仅检查地址是否在映射表中,还要验证当前对象的 vtable 是否与记录的 ghost vtable 匹配
243+
* 防止地址重用导致误判
241244
*/
242245
bool VtableHook::hasVtable(const void *obj)
243246
{
244247
quintptr **_obj = (quintptr**)(obj);
245-
246-
return objToGhostVfptr.contains(_obj);
248+
249+
if (!objToGhostVfptr.contains(_obj)) {
250+
return false;
251+
}
252+
253+
// 验证 vtable 是否匹配
254+
quintptr *ghost_vtable = objToGhostVfptr.value(obj);
255+
if (!ghost_vtable) {
256+
return false;
257+
}
258+
259+
// 检查当前对象的 vtable 指针是否指向我们记录的 ghost vtable
260+
if (*_obj != adjustToEntry(ghost_vtable)) {
261+
// vtable 不匹配,说明地址被重用了
262+
qCDebug(vtableHook) << "hasVtable: vtable mismatch! Address reused by different object."
263+
<< "obj:" << QString("0x%1").arg((quintptr)obj, 0, 16);
264+
return false;
265+
}
266+
267+
return true;
247268
}
248269

249270
void VtableHook::resetVtable(const void *obj)

0 commit comments

Comments
 (0)