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') 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")