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

unsafe-block test case and detector #38

Merged
merged 31 commits into from
Dec 22, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
20fda2f
Added unsafe-block test case
faculerena Nov 30, 2023
80c2fb7
Merge branch 'main' into unsafe-block
faculerena Dec 1, 2023
6317856
first iteration of unsafe-block detector
faculerena Dec 1, 2023
fff536b
change name on impl
faculerena Dec 1, 2023
faccbfd
cargo fmt
faculerena Dec 4, 2023
64c77b5
changed core-mem-forget to avoid-..
faculerena Dec 6, 2023
1a993ac
changed unsafe-block to avoid-*
faculerena Dec 6, 2023
ddf57e3
Update test-detectors.yml
faculerena Dec 6, 2023
ec9dab0
merge main
faculerena Dec 6, 2023
f3d866b
Merge branch 'core-mem-forget' of github.com:CoinFabrik/scout-soroban…
faculerena Dec 6, 2023
42981d8
Merge branch 'main' into core-mem-forget
faculerena Dec 6, 2023
d92a8f8
Merge branch 'main' into unsafe-block
faculerena Dec 6, 2023
4b10b56
forgot one name
faculerena Dec 6, 2023
c413c80
Merge branch 'core-mem-forget' of github.com:CoinFabrik/scout-soroban…
faculerena Dec 6, 2023
b570602
removed old name
faculerena Dec 6, 2023
a0baa26
package names
faculerena Dec 6, 2023
b667b5c
dup
faculerena Dec 6, 2023
c44d96e
dup
faculerena Dec 6, 2023
6aeec54
dup again
faculerena Dec 6, 2023
3035dfa
merge next branch
faculerena Dec 6, 2023
7a8c93c
changed to avoid-
faculerena Dec 6, 2023
27e64ed
detector fix
faculerena Dec 7, 2023
d3f4992
removed file
faculerena Dec 7, 2023
8a8b180
wrong folder name
faculerena Dec 7, 2023
104917e
detectors should be in alphabetical order or CI fails
faculerena Dec 7, 2023
6e0ab3a
Merge branch 'main' into unsafe-block
arlosiggio Dec 12, 2023
81be4eb
remove redefine in lint_message.rs
arlosiggio Dec 12, 2023
7a4eb6c
Merge branch 'main' into unsafe-block
faculerena Dec 15, 2023
e7c9f71
review changes
faculerena Dec 20, 2023
70bc352
Merge branch 'main' into unsafe-block
faculerena Dec 20, 2023
b6018a6
Update lint_message.rs
faculerena Dec 20, 2023
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
Prev Previous commit
Next Next commit
changed core-mem-forget to avoid-..
  • Loading branch information
faculerena committed Dec 6, 2023
commit 64c77b5e952b7af21ff1206fe38d63480b83e1ae
2 changes: 1 addition & 1 deletion .github/workflows/test-detectors.yml
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ jobs:
- macos-latest
test:
[
"core-mem-forget",
"avoid-avoid-avoid-core-mem-forget",
"divide-before-multiply",
"overflow-check",
"unprotected-update-current-contract-wasm",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,18 +41,18 @@ dylint_linting::impl_pre_expansion_lint! {
/// }
///```

pub CORE_MEM_FORGET,
pub AVOID_CORE_MEM_FORGET,
Warn,
Detector::CoreMemForget.get_lint_message(),
CoreMemForget::default()
Detector::AvoidCoreMemForget.get_lint_message(),
AvoidCoreMemForget::default()
}

#[derive(Default)]
pub struct CoreMemForget {
pub struct AvoidCoreMemForget {
stack: Vec<NodeId>,
}

impl EarlyLintPass for CoreMemForget {
impl EarlyLintPass for AvoidCoreMemForget {
fn check_item(&mut self, _cx: &EarlyContext, item: &Item) {
if self.in_test_item() || is_test_item(item) {
self.stack.push(item.id);
Expand All @@ -70,9 +70,9 @@ impl EarlyLintPass for CoreMemForget {
if path.segments[2].ident.name.to_string() == "forget";
then {

Detector::CoreMemForget.span_lint_and_help(
Detector::AvoidCoreMemForget.span_lint_and_help(
cx,
CORE_MEM_FORGET,
AVOID_CORE_MEM_FORGET,
expr.span,
"Instead, use the `let _ = ...` pattern or `.drop` method to forget the value.",
);
Expand Down Expand Up @@ -102,7 +102,7 @@ fn is_test_item(item: &Item) -> bool {
})
}

impl CoreMemForget {
impl AvoidCoreMemForget {
fn in_test_item(&self) -> bool {
!self.stack.is_empty()
}
Expand Down
2 changes: 1 addition & 1 deletion scout-audit-internal/src/detector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ impl Detector {
/// Returns the lint message for the detector.
pub const fn get_lint_message(&self) -> &'static str {
match self {
Detector::CoreMemForget => CORE_MEM_FORGET_LINT_MESSAGE,
Detector::AvoidCoreMemForget => AVOID_CORE_MEM_FORGET_LINT_MESSAGE,
Detector::DivideBeforeMultiply => DIVIDE_BEFORE_MULTIPLY_LINT_MESSAGE,
Detector::UnsafeExpect => UNSAFE_EXPECT_LINT_MESSAGE,
Detector::OverflowCheck => OVERFLOW_CHECK_LINT_MESSAGE,
Expand Down
2 changes: 1 addition & 1 deletion scout-audit-internal/src/detector/lint_message.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pub const CORE_MEM_FORGET_LINT_MESSAGE: &str =
pub const AVOID_CORE_MEM_FORGET_LINT_MESSAGE: &str =
"Use the `let _ = ...` pattern or `.drop()` method to forget the value";
pub const DIVIDE_BEFORE_MULTIPLY_LINT_MESSAGE: &str =
"Division before multiplication might result in a loss of precision";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
use soroban_sdk::{contract, contractimpl, contracttype};

#[contract]
pub struct CoreMemForget;
pub struct AvoidCoreMemForget;

#[contracttype]
#[derive(Eq, PartialEq)]
Expand All @@ -12,7 +12,7 @@ pub struct WithoutCopy {
}

#[contractimpl]
impl CoreMemForget {
impl AvoidCoreMemForget {
pub fn forget_something(n: WithoutCopy) -> u64 {
let _ = n;
0
Expand All @@ -27,7 +27,7 @@ mod tests {
fn test_forget_something() {
let test_value: WithoutCopy = WithoutCopy { a: 80, b: 60 };

let result = CoreMemForget::forget_something(test_value);
let result = AvoidCoreMemForget::forget_something(test_value);

assert_eq!(result, 0);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
use soroban_sdk::{contract, contractimpl, contracttype};

#[contract]
pub struct CoreMemForget;
pub struct AvoidCoreMemForget;

#[contracttype]
#[derive(Eq, PartialEq)]
Expand All @@ -12,7 +12,7 @@ pub struct WithoutCopy {
}

#[contractimpl]
impl CoreMemForget {
impl AvoidCoreMemForget {
pub fn forget_something(n: WithoutCopy) -> u64 {
core::mem::forget(n);
0
Expand All @@ -27,7 +27,7 @@ mod tests {
fn test_forget_something() {
let test_value: WithoutCopy = WithoutCopy { a: 80, b: 60 };

let result = CoreMemForget::forget_something(test_value);
let result = AvoidCoreMemForget::forget_something(test_value);

assert_eq!(result, 0);
}
Expand Down