Skip to content

Commit 5779126

Browse files
committed
DBO: Keep ref of parent in api to prevent ez uaf
1 parent 8509005 commit 5779126

3 files changed

Lines changed: 6 additions & 0 deletions

File tree

binaryninjaapi.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22401,6 +22401,8 @@ namespace BinaryNinja {
2240122401

2240222402
class DatabaseObject: public CoreRefCountObject<BNDatabaseObject, BNNewDatabaseObjectReference, BNFreeDatabaseObject>
2240322403
{
22404+
Ref<DatabaseObject> m_parent;
22405+
2240422406
public:
2240522407
explicit DatabaseObject(BNDatabaseObject* database);
2240622408

merge.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ using namespace std;
2727
DatabaseObject::DatabaseObject(BNDatabaseObject* object)
2828
{
2929
m_object = object;
30+
m_parent = GetParent();
3031
}
3132

3233

python/database.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,9 @@ def __init__(self, handle):
370370
self.handle = core.handle_of_type(handle, core.BNDatabaseObject)
371371
self._children = None
372372
self._dependencies = None
373+
# Hold a strong reference to parent because normally children have a weak ref
374+
# and their parent could be cleaned up without them
375+
self._parent = self.parent
373376

374377
def __del__(self):
375378
core.BNFreeDatabaseObject(self.handle)

0 commit comments

Comments
 (0)