Skip to content

Commit

Permalink
incorrect-equality: do not check addresses
Browse files Browse the repository at this point in the history
  • Loading branch information
ydm committed Mar 10, 2023
1 parent cb37650 commit 9dc5167
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion slither/detectors/statements/incorrect_strict_equality.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,14 @@ class IncorrectStrictEquality(AbstractDetector):
def is_direct_comparison(ir: Operation) -> bool:
return isinstance(ir, Binary) and ir.type == BinaryType.EQUAL

@staticmethod
def is_not_comparing_addresses(ir: Operation) -> bool:
"""
Comparing addresses strictly should not be flagged.
"""
addr = ElementaryType("address")
return ir.variable_left.type != addr or ir.variable_right.type != addr

@staticmethod
def is_any_tainted(
variables: List[
Expand Down Expand Up @@ -145,7 +153,12 @@ def tainted_equality_nodes(
for ir in node.irs_ssa:

# Filter to only tainted equality (==) comparisons
if self.is_direct_comparison(ir) and self.is_any_tainted(ir.used, taints, func):
if (
self.is_direct_comparison(ir)
and self.is_not_comparing_addresses(ir)
and self.is_any_tainted(ir.used, taints, func)
):
#
if func not in results:
results[func] = []
results[func].append(node)
Expand Down

0 comments on commit 9dc5167

Please sign in to comment.