Repository navigation
Fix: 2 issues (#914, #915) - #935
Open
wendyamoni-creator wants to merge 1 commit into
Open
wendyamoni-creator wants to merge 1 commit into
wendyamoni-creator wants to merge 1 commit into
Conversation
Co-authored-by: Simple Agent <agent@simple.dev>
|
@wendyamoni-creator Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #914
Closes #915
Issues
#914 analyzer: scanning a single
.rsfile does not follow out-of-linemod foo;declarations#915 checks: add
unchecked-negation-or-abs—-amount/.abs()oni128panics atMINSummary
For #914, factor module discovery into a helper shared by
scan_directory,scan_directory_with_checks, andscan_files; keep the visited set keyed by canonical path. For #915, reusecontractimpl_functions_excluding_testand the existing visitor patterns inoverflow.rs; ensure the check name is unique and thatrule_urlfollows the same format as other checks. The fixture crates need a minimalCargo.tomlmatching existingtest-contracts/*crates if the workspace requires it.Changes
.rsfile, out-of-linemod name;declarations are resolved recursively relative to the declaring file (name.rsorname/mod.rs, honouring#[path = "..."]). Maintain a visited set for cycle protection and de-duplication against already-scanned files, apply the same--excludeand generated-file skipping as directory walking, and emit warnings (not errors) for missing module files. Ensurescan_directory,scan_directory_with_checks, andscan_filesall use this discovery so a single-file scan matches a directory scan. (crates/analyzer/src/lib.rs)src/lib.rscontainingmod storage;andmod admin;, withsrc/storage.rsandsrc/admin/mod.rscontaining vulnerable contract code. Assert that scanning onlysrc/lib.rsproduces the same findings as scanning the directory, that missing module files produce a warning rather than an abort, and that excluded/generated module files are skipped. (crates/analyzer/tests/scan_files_api.rs).rsfile, out-of-linemod name;declarations are followed recursively (name.rs/name/mod.rs, honouring#[path]), with cycle protection, de-duplication, exclude/generated-file filtering, and warnings for missing module files, so single-file and directory scans agree. (docs/architecture.md)unchecked-negation-or-abscheck (Medium severity): walk#[contractimpl]functions excluding#[cfg(test)], flag unary-and.abs()applied to non-literal signed-integer operands, and suppress findings when the operand is guarded by a comparison againstMIN/0or whenchecked_neg,checked_abs,unsigned_abs, orsaturating_negis used. Setrule_urland include unit tests for vulnerable and safe forms. (crates/checks/src/overflow.rs)pub mod negation;(or re-export fromoverflow), exportUncheckedNegationOrAbsCheck, and addBox::new(UncheckedNegationOrAbsCheck)toall_checks_base()sodefault_checks()anddefault_checks_with_config()include it exactly once. (crates/checks/src/lib.rs)unchecked-negation-or-absentry to theFIXTUREStable mapping it to thenegationfixture base soregistry_consistency.rsrequirestest-contracts/negation-vulnerableandtest-contracts/negation-safe. (crates/checks/tests/registry_consistency.rs)negation_fixtures()callingassert_fixture_pair("negation", "unchecked-negation-or-abs")so the vulnerable fixture must produce the finding and the safe fixture must not. (crates/cli/tests/fixture_scans.rs)##unchecked-negation-or-abs(Medium)section documenting what it detects (unary-and.abs()on non-literal signed integers in#[contractimpl]methods), whyi128::MINnegation/abs traps underoverflow-checks = true, the guarded/checked/saturating/unsigned exceptions, limitations, and thetest-contracts/negation-vulnerable/andtest-contracts/negation-safe/fixtures. (docs/checks.md)examples/all-findings/src/lib.rswith a// Triggersunchecked-negation-or-abs`` comment that negates or calls.abs()on a non-literal signed integer inside the `#[contractimpl]` block, so the registry consistency test finds the trigger. (examples/all-findings/src/lib.rs)test-contracts/negation-vulnerable/src/lib.rscontaining a#[contractimpl]method that applies unary-and.abs()to a non-literali128amount without a MIN/0 guard, so the check fires. (test-contracts/negation-vulnerable/src/lib.rs)test-contracts/negation-safe/src/lib.rscontaining#[contractimpl]methods that guard againsti128::MIN/0before negating or usechecked_neg,checked_abs,unsigned_abs, orsaturating_neg, so the check does not fire. (test-contracts/negation-safe/src/lib.rs)