Skip to content

Commit

Permalink
Merge pull request #2628 from crytic/dev-fix-modifier-detector
Browse files Browse the repository at this point in the history
incorrect-modifier: Fix infinite loop
  • Loading branch information
smonicas authored Jan 16, 2025
2 parents 811d390 + 653cda5 commit 23074c6
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 1 deletion.
11 changes: 10 additions & 1 deletion slither/detectors/functions/modifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,21 +67,30 @@ class ModifierDefaultDetection(AbstractDetector):

def _detect(self) -> List[Output]:
results = []
# pylint: disable=too-many-nested-blocks
for c in self.contracts:
for mod in c.modifiers:
if mod.contract_declarer != c:
continue
# Walk down the tree, only looking at nodes in the outer scope
node = mod.entry_point
node_seen = []
while node is not None:
node_seen.append(node)
# If any node in the outer scope executes _; or reverts,
# we will never return a default value
if node.type == NodeType.PLACEHOLDER or is_revert(node):
break

# Move down, staying on the outer scope in branches
if len(node.sons) > 0:
node = _get_false_son(node) if node.contains_if() else node.sons[0]
if node.contains_if():
node = _get_false_son(node)
else:
if node.sons[0] in node_seen:
node = node.sons[1]
else:
node = node.sons[0]
else:
node = None
else:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,10 @@ contract Test {
_;
} while (i < 1);
}

modifier issue2619(bool b) {
while (b ? false : b) {}
_;
}

}
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,10 @@ contract Test {
_;
} while (i < 1);
}

modifier issue2619(bool b) {
while (b ? false : b) {}
_;
}

}
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,10 @@ contract Test {
_;
} while (i < 1);
}

modifier issue2619(bool b) {
while (b ? false : b) {}
_;
}

}
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,9 @@ contract Test {
_;
} while (i < 1);
}

modifier issue2619(bool b) {
while (b ? false : b) {}
_;
}
}
Binary file not shown.

0 comments on commit 23074c6

Please sign in to comment.