Skip to content

Commit d5ae5bd

Browse files
committed
Update lints
1 parent d0797af commit d5ae5bd

File tree

19 files changed

+447
-252
lines changed

19 files changed

+447
-252
lines changed

lints/insecure_account_close/Cargo.lock

Lines changed: 185 additions & 87 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lints/insecure_account_close/Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,15 @@ name = "secure"
3030
path = "ui/secure/src/lib.rs"
3131

3232
[dependencies]
33-
clippy_utils = { git = "https://github.com/rust-lang/rust-clippy", rev = "c995a8b5017766246ac5cfe66baa074eeee3a5a3" }
34-
dylint_linting = "2.0.2"
33+
clippy_utils = { git = "https://github.com/rust-lang/rust-clippy", rev = "0cb0f7636851f9fcc57085cf80197a2ef6db098f" }
34+
dylint_linting = "2.0.7"
3535
if_chain = "1.0.2"
3636
solana-lints = { path = "../../crate" }
3737

3838
[dev-dependencies]
3939
anchor-lang = "0.24.2"
4040
assert_cmd = "2.0.4"
41-
dylint_testing = "2.0.2"
41+
dylint_testing = "2.0.7"
4242
predicates = "2.1.1"
4343
tempfile = "3.3.0"
4444

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
[toolchain]
2-
channel = "nightly-2022-03-24"
2+
channel = "nightly-2022-06-30"
33
components = ["llvm-tools-preview", "rustc-dev"]

lints/insecure_account_close/src/lib.rs

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#![feature(bool_to_option)]
21
#![feature(rustc_private)]
32
#![recursion_limit = "256"]
43
#![warn(unused_extern_crates)]
@@ -12,10 +11,7 @@ use if_chain::if_chain;
1211
use rustc_ast::ast::{LitIntType, LitKind};
1312
use rustc_hir::{BinOpKind, Body, BorrowKind, Expr, ExprKind, LangItem, Mutability, QPath, UnOp};
1413
use rustc_lint::{LateContext, LateLintPass};
15-
use rustc_middle::{
16-
mir::interpret::ConstValue,
17-
ty::{ConstKind, TyKind, UintTy},
18-
};
14+
use rustc_middle::ty::{TyKind, UintTy};
1915
use solana_lints::utils::visit_expr_no_bodies;
2016

2117
dylint_linting::declare_late_lint! {
@@ -80,7 +76,7 @@ fn contains_initial_eight_byte_copy_slice<'tcx>(body: &'tcx Body<'tcx>) -> bool
8076
.is_some()
8177
}
8278

83-
fn is_initial_eight_byte_copy_from_slice<'tcx>(expr: &Expr<'tcx>) -> bool {
79+
fn is_initial_eight_byte_copy_from_slice(expr: &Expr<'_>) -> bool {
8480
if_chain! {
8581
if let ExprKind::MethodCall(method_name, args, _) = expr.kind;
8682
if method_name.ident.as_str() == "copy_from_slice";
@@ -130,8 +126,7 @@ fn is_eight_byte_array<'tcx>(cx: &LateContext<'tcx>, expr: &Expr<'tcx>) -> bool
130126
if_chain! {
131127
if let TyKind::Array(ty, length) = ty.kind();
132128
if *ty.kind() == TyKind::Uint(UintTy::U8);
133-
if let ConstKind::Value(ConstValue::Scalar(length)) = length.val();
134-
if let Ok(length) = length.to_machine_usize(&cx.tcx);
129+
if let Some(length) = length.try_eval_usize(cx.tcx, cx.param_env);
135130
if length == 8;
136131
then {
137132
true
@@ -145,7 +140,7 @@ fn contains_manual_clear<'tcx>(body: &'tcx Body<'tcx>) -> bool {
145140
visit_expr_no_bodies(&body.value, |expr| is_manual_clear(expr).then_some(())).is_some()
146141
}
147142

148-
fn is_manual_clear<'tcx>(expr: &Expr<'tcx>) -> bool {
143+
fn is_manual_clear(expr: &Expr<'_>) -> bool {
149144
if_chain! {
150145
if let Some(higher::ForLoop { body, .. }) = higher::ForLoop::hir(expr);
151146
if contains_zero_assignment(body);
@@ -158,7 +153,7 @@ fn is_manual_clear<'tcx>(expr: &Expr<'tcx>) -> bool {
158153
}
159154

160155
fn contains_zero_assignment<'tcx>(expr: &'tcx Expr<'tcx>) -> bool {
161-
visit_expr_no_bodies(expr, |expr| is_zero_assignment(expr)).is_some()
156+
visit_expr_no_bodies(expr, is_zero_assignment).is_some()
162157
}
163158

164159
fn is_zero_assignment<'tcx>(expr: &'tcx Expr<'tcx>) -> Option<&'tcx Expr<'tcx>> {

lints/missing_owner_check/Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,13 @@ name = "fixed-secure"
2626
path = "ui/fixed-secure/src/lib.rs"
2727

2828
[dependencies]
29-
clippy_utils = { git = "https://github.com/rust-lang/rust-clippy", rev = "7b2896a8fc9f0b275692677ee6d2d66a7cbde16a" }
30-
dylint_linting = "2.0.1"
29+
clippy_utils = { git = "https://github.com/rust-lang/rust-clippy", rev = "0cb0f7636851f9fcc57085cf80197a2ef6db098f" }
30+
dylint_linting = "2.0.7"
3131
if_chain = "1.0.2"
3232
solana-lints = { path = "../../crate" }
3333

3434
[dev-dependencies]
35-
dylint_testing = "2.0.1"
35+
dylint_testing = "2.0.7"
3636
anchor-lang = "0.24.2"
3737
spl-token = "3.3.0"
3838
anchor-spl = "0.24.2"
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
[toolchain]
2-
channel = "nightly-2022-02-24"
2+
channel = "nightly-2022-06-30"
33
components = ["llvm-tools-preview", "rustc-dev"]

lints/missing_owner_check/src/lib.rs

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@ extern crate rustc_span;
66

77
use clippy_utils::{diagnostics::span_lint, ty::match_type, SpanlessEq};
88
use if_chain::if_chain;
9-
use rustc_hir::{intravisit::{FnKind, Visitor, walk_expr}, Body, Expr, ExprKind, FnDecl, HirId};
9+
use rustc_hir::{
10+
intravisit::{walk_expr, FnKind, Visitor},
11+
Body, Expr, ExprKind, FnDecl, HirId,
12+
};
1013
use rustc_lint::{LateContext, LateLintPass};
1114
use rustc_span::Span;
1215
use solana_lints::{paths, utils::visit_expr_no_bodies};
@@ -52,8 +55,8 @@ impl<'tcx> LateLintPass<'tcx> for MissingOwnerCheck {
5255
cx,
5356
MISSING_OWNER_CHECK,
5457
account_expr.span,
55-
"this Account struct is used but there is no check on its owner field"
56-
)
58+
"this Account struct is used but there is no check on its owner field",
59+
);
5760
}
5861
}
5962
}
@@ -65,7 +68,10 @@ struct AccountUses<'cx, 'tcx> {
6568
uses: Vec<&'tcx Expr<'tcx>>,
6669
}
6770

68-
fn get_referenced_accounts<'tcx>(cx: &LateContext<'tcx>, body: &'tcx Body<'tcx>) -> Vec<&'tcx Expr<'tcx>> {
71+
fn get_referenced_accounts<'tcx>(
72+
cx: &LateContext<'tcx>,
73+
body: &'tcx Body<'tcx>,
74+
) -> Vec<&'tcx Expr<'tcx>> {
6975
let mut accounts = AccountUses {
7076
cx,
7177
uses: Vec::new(),
@@ -87,20 +93,24 @@ impl<'cx, 'tcx> Visitor<'tcx> for AccountUses<'cx, 'tcx> {
8793
self.uses.push(expr);
8894
}
8995
}
90-
walk_expr(self, expr)
96+
walk_expr(self, expr);
9197
}
9298
}
9399

94100
fn contains_owner_use<'tcx>(
95-
cx: &LateContext<'tcx>,
101+
cx: &LateContext<'tcx>,
96102
body: &'tcx Body<'tcx>,
97-
account_expr: &Expr<'tcx>
103+
account_expr: &Expr<'tcx>,
98104
) -> bool {
99105
visit_expr_no_bodies(&body.value, |expr| uses_owner_field(cx, expr, account_expr))
100106
}
101107

102108
/// Checks if `expr` is an owner field reference on `account_expr`
103-
fn uses_owner_field<'tcx>(cx: &LateContext<'tcx>, expr: &Expr<'tcx>, account_expr: &Expr<'tcx>) -> bool {
109+
fn uses_owner_field<'tcx>(
110+
cx: &LateContext<'tcx>,
111+
expr: &Expr<'tcx>,
112+
account_expr: &Expr<'tcx>,
113+
) -> bool {
104114
if_chain! {
105115
if let ExprKind::Field(object, field_name) = expr.kind;
106116
// TODO: add check for key, is_signer

lints/missing_owner_check/ui/fixed-secure/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ edition = "2021"
88

99
[lib]
1010
crate-type = ["cdylib", "lib"]
11-
name = "account_data_matching_secure_fixed"
11+
name = "owner_checks_secure_fixed"
1212

1313
[features]
1414
no-entrypoint = []
@@ -20,4 +20,4 @@ default = []
2020
[dependencies]
2121
anchor-lang = "0.24.2"
2222
anchor-spl = "0.24.2"
23-
spl-token = "3.2.0"
23+
spl-token = "3.2.0"

lints/missing_owner_check/ui/fixed-secure/src/lib.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
use anchor_lang::prelude::*;
2-
use anchor_lang::solana_program::{
3-
program_pack::Pack,
4-
entrypoint::ProgramResult,
5-
};
2+
use anchor_lang::solana_program::{entrypoint::ProgramResult, program_pack::Pack};
63
use spl_token::state::Account as SplTokenAccount;
74

85
declare_id!("Fg6PaFpoGXkYsidMpWTK6W2BeZ7FEfcYkg476zPFsLnS");

lints/missing_owner_check/ui/insecure/Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
[package]
2-
name = "account-data-matching-insecure"
2+
name = "owner-checks-insecure"
33
version = "0.1.0"
44
description = "Created with Anchor"
55
edition = "2018"
66

77
[lib]
88
crate-type = ["cdylib", "lib"]
9-
name = "account_data_matching_insecure"
9+
name = "owner_checks_insecure"
1010

1111
[features]
1212
no-entrypoint = []
@@ -18,4 +18,4 @@ default = []
1818
[dependencies]
1919
anchor-lang = "0.24.2"
2020
anchor-spl = "0.24.2"
21-
spl-token = "3.2.0"
21+
spl-token = "3.2.0"

0 commit comments

Comments
 (0)