Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

incorrect-equality: do not check addresses #1713

Merged
merged 1 commit into from
May 5, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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: Binary) -> bool:
"""
Comparing addresses strictly should not be flagged.
"""
addr = ElementaryType("address")
return ir.variable_left.type != addr or ir.variable_right.type != addr
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If something like Contract(address(0x0)) == Contract(address(0x0)) is used, is_not_comparing_addresses won't filter it out. We would need to add something like isinstance(ir.variable_left.type, UserDefinedType) and isinstance(ir.variable_left.type.type, Contract). It'd be helpful to add a test case for both the address and contract case so that we can be sure of the modifications and prevent regressions in the future.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

alright, will do that


@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