From 0b87becbf354bed4e5a91bc77642f675a50c12f0 Mon Sep 17 00:00:00 2001 From: nofiv <41523109+nofiv@users.noreply.github.com> Date: Tue, 16 Jun 2020 12:52:51 +0200 Subject: [PATCH 1/2] Sanity check for empty AsmBlocks --- miasm/core/asmblock.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/miasm/core/asmblock.py b/miasm/core/asmblock.py index f412de869..a0fee580d 100644 --- a/miasm/core/asmblock.py +++ b/miasm/core/asmblock.py @@ -623,6 +623,11 @@ def sanity_check(self): for loc_key in self._nodes: if loc_key not in self._loc_key_to_block: raise RuntimeError("Not supported yet: every node must have a corresponding AsmBlock") + + block = self.loc_key_to_block(loc_key) + if not block.lines and not isinstance(block, AsmBlockBad): + raise RuntimeError("Blocks cannot be empty") + # No next constraint to self if (loc_key, loc_key) in next_edges: raise RuntimeError('Bad constraint: self in next') From 397c4834bf5de78b648686b6a3c9eab5a16b4693 Mon Sep 17 00:00:00 2001 From: nofiv <41523109+nofiv@users.noreply.github.com> Date: Wed, 17 Jun 2020 13:19:09 +0200 Subject: [PATCH 2/2] Fix tests for empty AsmBlock sanity check --- test/core/asmblock.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/test/core/asmblock.py b/test/core/asmblock.py index 47f925690..2ab562185 100644 --- a/test/core/asmblock.py +++ b/test/core/asmblock.py @@ -139,6 +139,13 @@ def remove_useless_blocks(d_g, graph): assert len(list(asmcfg.get_bad_blocks_predecessors(strict=True))) == 0 ## Sanity check +flag = False +try: + asmcfg.sanity_check() +except RuntimeError: + flag = True +assert flag +my_block.lines = [first_block.lines[0]] asmcfg.sanity_check() ### Next on itself testlabel_nextitself = mdis.loc_db.get_or_create_name_location("testlabel_nextitself")