-
Notifications
You must be signed in to change notification settings - Fork 261
Fix UAF when passing TypeBuilder objects into some APIs #7566
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -5286,8 +5286,8 @@ def define_data_var( | |||||||||||||
|
|
||||||||||||||
| if isinstance(var_type, str): | ||||||||||||||
| (var_type, _) = self.parse_type_string(var_type) | ||||||||||||||
| tc = var_type._to_core_struct() | ||||||||||||||
| core.BNDefineDataVariable(self.handle, addr, tc) | ||||||||||||||
| tc = var_type.immutable_copy() | ||||||||||||||
| core.BNDefineDataVariable(self.handle, addr, tc._to_core_struct()) | ||||||||||||||
|
|
||||||||||||||
| if name is not None: | ||||||||||||||
| if isinstance(name, str): | ||||||||||||||
|
|
@@ -5321,8 +5321,11 @@ def define_user_data_var( | |||||||||||||
|
|
||||||||||||||
| if isinstance(var_type, str): | ||||||||||||||
| (var_type, _) = self.parse_type_string(var_type) | ||||||||||||||
| tc = var_type._to_core_struct() | ||||||||||||||
| core.BNDefineUserDataVariable(self.handle, addr, tc) | ||||||||||||||
|
|
||||||||||||||
| # this var_type temporary is essential! It holds the reference to the immutable type | ||||||||||||||
| # until after BNDefineUserDataVariable takes the reference. | ||||||||||||||
| var_type = var_type.immutable_copy() | ||||||||||||||
| core.BNDefineUserDataVariable(self.handle, addr, var_type._to_core_struct()) | ||||||||||||||
|
|
||||||||||||||
| if name is not None: | ||||||||||||||
| if isinstance(name, str): | ||||||||||||||
|
|
@@ -8377,6 +8380,7 @@ def define_type( | |||||||||||||
| default_name = new_name | ||||||||||||||
| assert default_name is not None, "default_name can only be None if named type is derived from string passed to type_obj" | ||||||||||||||
| name = _types.QualifiedName(default_name)._to_core_struct() | ||||||||||||||
| type_obj = type_obj.immutable_copy() | ||||||||||||||
| reg_name = core.BNDefineAnalysisType(self.handle, type_id, name, type_obj.handle) | ||||||||||||||
| result = _types.QualifiedName._from_core_struct(reg_name) | ||||||||||||||
| core.BNFreeQualifiedName(reg_name) | ||||||||||||||
|
|
@@ -8407,6 +8411,7 @@ def define_user_type(self, name: Optional['_types.QualifiedNameType'], type_obj: | |||||||||||||
| if name is None: | ||||||||||||||
| raise ValueError("name can only be None if named type is derived from string passed to type_obj") | ||||||||||||||
| _name = _types.QualifiedName(name)._to_core_struct() | ||||||||||||||
| type_obj = type_obj.immutable_copy() | ||||||||||||||
| core.BNDefineUserAnalysisType(self.handle, _name, type_obj.handle) | ||||||||||||||
|
|
||||||||||||||
| def define_types(self, types: List[Tuple[str, Optional['_types.QualifiedNameType'], StringOrType]], progress_func: Optional[ProgressFuncType]) -> Mapping[str, '_types.QualifiedName']: | ||||||||||||||
|
|
@@ -8685,7 +8690,8 @@ def export_type_to_library(self, lib: typelibrary.TypeLibrary, name: Optional[st | |||||||||||||
| (type_obj, new_name) = self.parse_type_string(type_obj) | ||||||||||||||
| if name is None: | ||||||||||||||
| _name = new_name | ||||||||||||||
| if not isinstance(type_obj, (_types.Type, _types.TypeBuilder)): | ||||||||||||||
| type_obj = type_obj.immutable_copy() | ||||||||||||||
| if not isinstance(type_obj, _types.Type): | ||||||||||||||
| raise TypeError("type_obj must be a Type object") | ||||||||||||||
| if _name is None: | ||||||||||||||
| raise ValueError("name can only be None if named type is derived from string passed to type_obj") | ||||||||||||||
|
|
@@ -8719,7 +8725,8 @@ def export_object_to_library( | |||||||||||||
| (type_obj, new_name) = self.parse_type_string(type_obj) | ||||||||||||||
| if name is None: | ||||||||||||||
| _name = new_name | ||||||||||||||
| if not isinstance(type_obj, (_types.Type, _types.TypeBuilder)): | ||||||||||||||
| type_obj = type_obj.immutable_copy() | ||||||||||||||
| if not isinstance(type_obj, _types.Type): | ||||||||||||||
| raise TypeError("type_obj must be a Type object") | ||||||||||||||
|
Comment on lines
+8728
to
8730
|
||||||||||||||
| type_obj = type_obj.immutable_copy() | |
| if not isinstance(type_obj, _types.Type): | |
| raise TypeError("type_obj must be a Type object") | |
| elif not isinstance(type_obj, _types.Type): | |
| raise TypeError("type_obj must be a Type object or a type string") | |
| type_obj = type_obj.immutable_copy() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The isinstance check at line 8694 is now redundant since
immutable_copy()always returns aTypeobject. This check should be moved before theimmutable_copy()call to validate the input parameter, or the error message should be updated to reflect that the conversion failed. The same pattern occurs at lines 8728-8730.