Skip to content

Commit

Permalink
BUGFIX: Fix issue #11 which resulted in an infinite loop when walking…
Browse files Browse the repository at this point in the history
… through nodes to resolve orphan blocks.
  • Loading branch information
msuiche committed Aug 2, 2017
1 parent 42ad4a5 commit c7ac851
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
18 changes: 14 additions & 4 deletions porosity/porosity/Contract.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -375,19 +375,29 @@ Contract::walkAndConnectNodes(
//
uint32_t next = _block;
while (true) {
auto block = m_listbasicBlockInfo.find(next);
auto block = m_listbasicBlockInfo.find(next); // getBlockAt()
if (block == m_listbasicBlockInfo.end()) break;

if (block->second.walkedNode) break;

next = block->second.dstDefault;

// printf("hash = 0x%x, block = 0x%x, default = 0x%x, JUMPI = 0x%x\n", _hash, _block, block->second.dstDefault, block->second.dstJUMPI);
if (block->second.dstJUMPI) {
block->second.walkedNode = true;
walkAndConnectNodes(_hash, block->second.dstJUMPI);
}

if (!next) break;
if (next == NODE_DEADEND) {
auto exitNode = m_exitNodesByHash.find(_hash);
block->second.dstDefault = exitNode->second;
block->second.nextDefault = getBlockAt(block->second.dstDefault);
auto exitNode = m_exitNodesByHash.find(_hash); // getBlockAt()
if (exitNode != m_exitNodesByHash.end()) {
block->second.dstDefault = exitNode->second;
}

if (!block->second.nextDefault) {
block->second.nextDefault = getBlockAt(block->second.dstDefault);
}
break; // next
}
}
Expand Down
4 changes: 4 additions & 0 deletions porosity/porosity/Instruction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,10 @@ void dev::eth::eachInstruction(
size_t additional = 0;
if (isValidInstruction(instr))
additional = instructionInfo(instr).additional;
else {
// printf("Invalid instruction. Aborting...\n");
return;
}

uint32_t offset = std::distance(_mem.begin(), it);
u256 data;
Expand Down
1 change: 1 addition & 0 deletions porosity/porosity/PorosityDefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ typedef struct _BasicBlockInfo
string name;

bool visited;
bool walkedNode;
u256 dominators;

ConditionAttribute condAttr;
Expand Down

0 comments on commit c7ac851

Please sign in to comment.