Skip to content

Commit

Permalink
Merge branch 'main' into 61-unprotected-mapping-operation
Browse files Browse the repository at this point in the history
  • Loading branch information
jgcrosta committed Mar 25, 2024
2 parents 889caa1 + fb2485f commit 946f900
Show file tree
Hide file tree
Showing 19 changed files with 177 additions and 66 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ cargo +nightly install cargo-dylint dylint-link
Afterwards, install Scout with the following command:

```bash
cargo +nightly install cargo-scout-audit-soroban
cargo install cargo-scout-audit
```

### CLI

To run Scout on your project, navigate to its root directory and execute the following command:

```bash
cargo scout-audit-soroban
cargo scout-audit
```

### VSCode Extension
Expand Down
6 changes: 3 additions & 3 deletions detectors/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ exclude = [".cargo", "target"]
resolver = "2"

[workspace.dependencies]
dylint_linting = "2.1.5"
dylint_linting = { version = "=2.6.1", package = "scout-audit-dylint-linting"}
dylint_testing = "2.1.5"
if_chain = "1.0.2"

scout-audit-clippy-utils = { version = "=0.2.1", path = "../scout-audit-clippy-utils" }
scout-audit-internal = { path = "../scout-audit-internal", features = ["detector", "lint_helper"] }
scout-audit-clippy-utils = { version = "=0.2.3" }
scout-audit-internal = { version="=0.2.4", features = ["detector", "lint_helper"] }
4 changes: 2 additions & 2 deletions detectors/avoid-core-mem-forget/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use if_chain::if_chain;
use rustc_ast::{Expr, ExprKind, Item, NodeId};
use rustc_lint::{EarlyContext, EarlyLintPass};
use rustc_span::sym;
use scout_audit_internal::Detector;
use scout_audit_internal::{DetectorImpl, SorobanDetector as Detector};

dylint_linting::impl_pre_expansion_lint! {
/// ### What it does
Expand Down Expand Up @@ -43,7 +43,7 @@ dylint_linting::impl_pre_expansion_lint! {
pub AVOID_CORE_MEM_FORGET,
Warn,
Detector::AvoidCoreMemForget.get_lint_message(),
"",
AvoidCoreMemForget::default()
}

Expand Down
6 changes: 3 additions & 3 deletions detectors/avoid-panic-error/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use rustc_ast::{
use rustc_lint::{EarlyContext, EarlyLintPass};
use rustc_span::{sym, Span};
use scout_audit_clippy_utils::sym;
use scout_audit_internal::Detector;
use scout_audit_internal::{DetectorImpl, SorobanDetector as Detector};

dylint_linting::impl_pre_expansion_lint! {
/// ### What it does
Expand Down Expand Up @@ -57,7 +57,7 @@ dylint_linting::impl_pre_expansion_lint! {
/// ```
pub AVOID_PANIC_ERROR,
Warn,
Detector::AvoidPanicError.get_lint_message(),
"",
AvoidPanicError::default()
}

Expand Down Expand Up @@ -182,6 +182,6 @@ fn capitalize_err_msg(s: &str) -> String {
fn is_test_token_present(token_stream: &TokenStream) -> bool {
token_stream.trees().any(|tree| match tree {
TokenTree::Token(token, _) => token.is_ident_named(sym::test),
TokenTree::Delimited(_, _, token_stream) => is_test_token_present(token_stream),
TokenTree::Delimited(_, _, _, token_stream) => is_test_token_present(token_stream),
})
}
4 changes: 2 additions & 2 deletions detectors/avoid-unsafe-block/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use rustc_hir::{
};
use rustc_lint::LateLintPass;
use rustc_span::Span;
use scout_audit_internal::Detector;
use scout_audit_internal::{DetectorImpl, SorobanDetector as Detector};

dylint_linting::declare_late_lint! {
/// ### What it does
Expand Down Expand Up @@ -50,7 +50,7 @@ dylint_linting::declare_late_lint! {
/// ```
pub AVOID_UNSAFE_BLOCK,
Warn,
Detector::AvoidUnsafeBlock.get_lint_message()
""
}

impl<'tcx> LateLintPass<'tcx> for AvoidUnsafeBlock {
Expand Down
34 changes: 16 additions & 18 deletions detectors/divide-before-multiply/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use rustc_middle::mir::{
use rustc_middle::ty::TyKind;
use rustc_span::def_id::DefId;
use rustc_span::Span;
use scout_audit_internal::Detector;
use scout_audit_internal::{DetectorImpl, SorobanDetector as Detector};

dylint_linting::declare_late_lint! {
/// ### What it does
Expand All @@ -45,7 +45,7 @@ dylint_linting::declare_late_lint! {
/// ```
pub DIVIDE_BEFORE_MULTIPLY,
Warn,
Detector::DivideBeforeMultiply.get_lint_message()
""
}

fn get_divisions_inside_expr(expr: &Expr<'_>) -> Vec<Span> {
Expand Down Expand Up @@ -298,23 +298,21 @@ fn navigate_trough_basicblocks<'tcx>(
spans,
);
}
TerminatorKind::InlineAsm { destination, .. } => {
if let Option::Some(dest) = destination {
navigate_trough_basicblocks(
*dest,
bbs,
def_ids,
tainted_places,
visited_bbs,
spans,
);
}
TerminatorKind::InlineAsm {
destination: Some(dest),
..
} => {
navigate_trough_basicblocks(
*dest,
bbs,
def_ids,
tainted_places,
visited_bbs,
spans,
);
}
TerminatorKind::GeneratorDrop
| TerminatorKind::UnwindResume
| TerminatorKind::UnwindTerminate(_)
| TerminatorKind::Return
| TerminatorKind::Unreachable => {}

_ => {}
}
}
}
Expand Down
5 changes: 2 additions & 3 deletions detectors/dos-unbounded-operation/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use rustc_hir::{
};
use rustc_lint::{LateContext, LateLintPass};
use rustc_span::{def_id::LocalDefId, Span};
use scout_audit_internal::Detector;
use scout_audit_internal::{DetectorImpl, SorobanDetector as Detector};

dylint_linting::declare_late_lint!(
pub DOS_UNBOUNDED_OPERATION,
Expand Down Expand Up @@ -92,13 +92,12 @@ impl<'tcx> Visitor<'tcx> for ForLoopVisitor {
if let ExprKind::Call(call_func, call_args) = match_expr.kind;
// Check the function call
if let ExprKind::Path(qpath) = &call_func.kind;
if let QPath::LangItem(LangItem::IntoIterIntoIter, _, _) = qpath;
if let QPath::LangItem(LangItem::IntoIterIntoIter, _) = qpath;
// Check if a Range is used
if let ExprKind::Struct(struct_lang_item, struct_expr, _) = call_args.first().unwrap().kind;
if let QPath::LangItem(
LangItem::Range | LangItem::RangeInclusiveStruct | LangItem::RangeInclusiveNew,
_,
_,
) = struct_lang_item;
// Get the start and end of the range
if let Some(start_expr) = struct_expr.first();
Expand Down
4 changes: 2 additions & 2 deletions detectors/insufficiently-random-values/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ extern crate rustc_hir;
use if_chain::if_chain;
use rustc_hir::{BinOpKind, Expr, ExprKind};
use rustc_lint::{LateContext, LateLintPass};
use scout_audit_internal::Detector;
use scout_audit_internal::{DetectorImpl, SorobanDetector as Detector};

dylint_linting::declare_late_lint! {
/// ### What it does
Expand All @@ -21,7 +21,7 @@ dylint_linting::declare_late_lint! {
///
pub INSUFFICIENTLY_RANDOM_VALUES,
Warn,
Detector::InsufficientlyRandomValues.get_lint_message()
""
}

impl<'tcx> LateLintPass<'tcx> for InsufficientlyRandomValues {
Expand Down
4 changes: 2 additions & 2 deletions detectors/overflow-check/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ extern crate rustc_span;
use std::fs;

use rustc_lint::EarlyLintPass;
use scout_audit_internal::Detector;
use scout_audit_internal::{DetectorImpl, SorobanDetector as Detector};

dylint_linting::declare_early_lint! {
/// ### What it does
Expand All @@ -19,7 +19,7 @@ dylint_linting::declare_early_lint! {
/// wants explicitly checked, wrapping or saturating arithmetic.
pub OVERFLOW_CHECK,
Warn,
Detector::OverflowCheck.get_lint_message()
""
}

impl EarlyLintPass for OverflowCheck {
Expand Down
2 changes: 1 addition & 1 deletion detectors/rust-toolchain
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[toolchain]
channel = "nightly-2023-09-29"
channel = "nightly-2023-12-16"
components = ["llvm-tools-preview", "rustc-dev"]
4 changes: 2 additions & 2 deletions detectors/set-contract-storage/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use rustc_hir::{Body, FnDecl};
use rustc_hir::{Expr, ExprKind};
use rustc_lint::{LateContext, LateLintPass};
use rustc_span::Span;
use scout_audit_internal::Detector;
use scout_audit_internal::{DetectorImpl, SorobanDetector as Detector};

dylint_linting::declare_late_lint! {
/// ### What it does
Expand All @@ -38,7 +38,7 @@ dylint_linting::declare_late_lint! {
/// ```
pub SET_STORAGE_WARN,
Warn,
Detector::SetContractStorage.get_lint_message()
""
}

impl<'tcx> LateLintPass<'tcx> for SetStorageWarn {
Expand Down
4 changes: 2 additions & 2 deletions detectors/soroban-version/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use std::{io::Error, process::Command};

use rustc_ast::Crate;
use rustc_lint::{EarlyContext, EarlyLintPass, LintContext};
use scout_audit_internal::Detector;
use scout_audit_internal::{DetectorImpl, SorobanDetector as Detector};
use semver::Version;
use serde_json::Value;

Expand All @@ -20,7 +20,7 @@ dylint_linting::declare_early_lint! {
/// Using an outdated version of soroban could lead to security vulnerabilities, bugs, and other issues.
pub CHECK_SOROBAN_VERSION,
Warn,
Detector::SorobanVersion.get_lint_message()
""
}

impl EarlyLintPass for CheckSorobanVersion {
Expand Down
31 changes: 14 additions & 17 deletions detectors/unprotected-update-current-contract-wasm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ use rustc_middle::mir::{BasicBlock, BasicBlocks, Const, Operand, TerminatorKind}
use rustc_middle::ty::TyKind;
use rustc_span::def_id::DefId;
use rustc_span::Span;
use scout_audit_internal::Detector;
use scout_audit_internal::{DetectorImpl, SorobanDetector as Detector};

dylint_linting::impl_late_lint! {
pub UNPROTECTED_UPDATE_CURRENT_CONTRACT_WASM,
Warn,
Detector::UnprotectedUpdateCurrentContractWasm.get_lint_message(),
"",
UnprotectedUpdateCurrentContractWasm::default()
}

Expand Down Expand Up @@ -179,22 +179,19 @@ impl<'tcx> LateLintPass<'tcx> for UnprotectedUpdateCurrentContractWasm {
visited,
));
}
TerminatorKind::InlineAsm { destination, .. } => {
if let Some(udestination) = destination {
ret_vec.append(&mut navigate_trough_basicblocks(
bbs,
*udestination,
checked,
uuf_storage,
visited,
));
}
TerminatorKind::InlineAsm {
destination: Some(udestination),
..
} => {
ret_vec.append(&mut navigate_trough_basicblocks(
bbs,
*udestination,
checked,
uuf_storage,
visited,
));
}
TerminatorKind::Return
| TerminatorKind::Unreachable
| TerminatorKind::GeneratorDrop
| TerminatorKind::UnwindResume
| TerminatorKind::UnwindTerminate(_) => {}
_ => {}
}
ret_vec
}
Expand Down
4 changes: 2 additions & 2 deletions detectors/unsafe-expect/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use rustc_hir::{
};
use rustc_lint::LateLintPass;
use rustc_span::{Span, Symbol};
use scout_audit_internal::Detector;
use scout_audit_internal::{DetectorImpl, SorobanDetector as Detector};

dylint_linting::declare_late_lint! {
/// ### What it does
Expand Down Expand Up @@ -45,7 +45,7 @@ dylint_linting::declare_late_lint! {
/// ```
pub UNSAFE_EXPECT,
Warn,
Detector::UnsafeExpect.get_lint_message()
""
}

impl<'tcx> LateLintPass<'tcx> for UnsafeExpect {
Expand Down
4 changes: 2 additions & 2 deletions detectors/unsafe-unwrap/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use rustc_hir::{
};
use rustc_lint::LateLintPass;
use rustc_span::{Span, Symbol};
use scout_audit_internal::Detector;
use scout_audit_internal::{DetectorImpl, SorobanDetector as Detector};

dylint_linting::declare_late_lint! {
/// ### What it does
Expand Down Expand Up @@ -45,7 +45,7 @@ dylint_linting::declare_late_lint! {
/// ```
pub UNSAFE_UNWRAP,
Warn,
Detector::UnsafeUnwrap.get_lint_message()
""
}

impl<'tcx> LateLintPass<'tcx> for UnsafeUnwrap {
Expand Down
Loading

0 comments on commit 946f900

Please sign in to comment.