Skip to content

feat(lint): add missing-zero-check#14460

Open
stevencartavia wants to merge 1 commit intomasterfrom
steven/missing-zero-check-lint
Open

feat(lint): add missing-zero-check#14460
stevencartavia wants to merge 1 commit intomasterfrom
steven/missing-zero-check-lint

Conversation

@stevencartavia
Copy link
Copy Markdown
Collaborator

Adds a missing-zero-check lint that flags address parameters of externally-callable functions and constructors used in state writes or value transfers (call/delegatecall/staticcall/transfer/send) without a prior require/assert/if check.

Testing

cargo run -p forge -- lint crates/lint/testdata/MissingZeroCheck.sol

let n = name.name;
if n == kw::Call
|| n == kw::Delegatecall
|| n == kw::Staticcall
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Staticcall is read-only, unsure it makes sense to flag it.

Comment on lines +274 to +279
if self.guard_depth > 0 {
self.guarded.extend(srcs.iter().copied());
}
if self.sink_depth > 0 {
self.sinks.extend(srcs.iter().copied());
}
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Guard ordering is not enforced.

This seems to be a false negative:

function guardAfterSink(address a) external {
    owner = a; // sink: 'a' written to state
    require(a != address(0)); // guard too late, but marks 'a' as guarded anyway
} 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

2 participants