summaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
authorJosh Watson <josh@joshwatson.com>2017-10-29 12:51:23 -0400
committerplafosse <peter@vector35.com>2017-10-29 12:51:23 -0400
commit75242aecc30c565ee56d3e74ec2e2dd502a6f073 (patch)
treef89ccecffa177d1aeef2e684f71ac6a15c9a7d60 /python
parent77e09a2d02efbb2d6aa9758b503e37cbe7655f7f (diff)
Fixed possible IndexError in Function.get_*_at methods (#775)
`Function.get_low_level_il_at` and `Function.get_lifted_il_at` methods could raise an IndexError because proper checking was not performed on the index returned by the core method that retrieves the IL instruction index of the requested instruction. The methods now check this value to see if it is equal to the length of the IL function, and if so, returns `None` instead. The onus of checking for `None` will be on the user, but at least they shouldn't have to wrap this in a try/except block anymore.
Diffstat (limited to 'python')
-rw-r--r--python/function.py16
1 files changed, 14 insertions, 2 deletions
diff --git a/python/function.py b/python/function.py
index 5daa7b2a..9aafdf52 100644
--- a/python/function.py
+++ b/python/function.py
@@ -727,7 +727,13 @@ class Function(object):
"""
if arch is None:
arch = self.arch
- return self.low_level_il[core.BNGetLowLevelILForInstruction(self.handle, arch.handle, addr)]
+
+ idx = core.BNGetLowLevelILForInstruction(self.handle, arch.handle, addr)
+
+ if idx == len(self.low_level_il):
+ return None
+
+ return self.low_level_il[idx]
def get_low_level_il_exits_at(self, addr, arch=None):
if arch is None:
@@ -878,7 +884,13 @@ class Function(object):
def get_lifted_il_at(self, addr, arch=None):
if arch is None:
arch = self.arch
- return self.lifted_il[core.BNGetLiftedILForInstruction(self.handle, arch.handle, addr)]
+
+ idx = core.BNGetLiftedILForInstruction(self.handle, arch.handle, addr)
+
+ if idx == len(self.lifted_il):
+ return None
+
+ return self.lifted_il[idx]
def get_lifted_il_flag_uses_for_definition(self, i, flag):
flag = self.arch.get_flag_index(flag)