fkie-cad / dewolf

A research decompiler implemented as a Binary Ninja plugin.
GNU Lesser General Public License v2.1
176 stars 9 forks source link

IndexError: list index out of range in remove_stack_canary #131

Closed jnhols closed 1 year ago

jnhols commented 1 year ago

What happened?

The decompiler crashes with an IndexError in remove_stack_canary during preprocessing.

Traceback (most recent call last):
    File ""/home/ubuntu/.binaryninja/plugins/dewolf/decompile.py"", line 80, in <module>
main(Decompiler)
    File ""/home/ubuntu/.binaryninja/plugins/dewolf/decompiler/util/commandline.py"", line 65, in main
task = decompiler.decompile(function_name, options)
    File ""/home/ubuntu/.binaryninja/plugins/dewolf/decompile.py"", line 55, in decompile
pipeline.run(task)
    File ""/home/ubuntu/.binaryninja/plugins/dewolf/decompiler/pipeline/pipeline.py"", line 97, in run
instance.run(task)
    File ""/home/ubuntu/.binaryninja/plugins/dewolf/decompiler/pipeline/preprocessing/remove_stack_canary.py"", line 24, in run
self._patch_canary(fail_node)
    File ""/home/ubuntu/.binaryninja/plugins/dewolf/decompiler/pipeline/preprocessing/remove_stack_canary.py"", line 49, in _patch_canary
self._patch_branch_condition(pred)
    File ""/home/ubuntu/.binaryninja/plugins/dewolf/decompiler/pipeline/preprocessing/remove_stack_canary.py"", line 56, in _patch_branch_condition
branch_instruction = node.instructions[-1]
IndexError: list index out of range

How to reproduce?

Decompile print_dir in ls, get_dev in df or main in one of the other samples given below.

remove_stack_canary_index_error.zip

Affected Binary Ninja Version(s)

3.2.3814

NeoQuix commented 1 year ago

Happens because an empty node is in between the stack canary check block and the canary fail method block. Can't really see a logic when exactly a empty BasicBlock is inserted in between two nodes (maybe someone can explain?).

Anyways there is always only one block, so removing the block in between as well would solve the problem.

NeoQuix commented 1 year ago

/cib

github-actions[bot] commented 1 year ago

Branch issue-131-IndexError_list_index_out_of_range_in_remove_stack_canary created!