Skip to content

Commit

Permalink
Merge pull request #1811 from greenbone/fix-warnings-and-clippy-lints
Browse files Browse the repository at this point in the history
Fix warnings and clippy lints
  • Loading branch information
Tehforsch authored Jan 16, 2025
2 parents fd5c4ca + b2f7e24 commit 85b7559
Show file tree
Hide file tree
Showing 14 changed files with 41 additions and 46 deletions.
4 changes: 2 additions & 2 deletions rust/src/nasl/builtin/http/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,10 +199,10 @@ impl NaslHttp {
}

/// Perform request with the given method.
async fn http2_req<'a>(
async fn http2_req(
&self,
register: &Register,
ctx: &Context<'a>,
ctx: &Context<'_>,
method: Method,
) -> Result<NaslValue, FnError> {
let handle_id = match register.named("handle") {
Expand Down
24 changes: 15 additions & 9 deletions rust/src/nasl/builtin/raw_ip/packet_forgery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,8 @@ fn forge_ip_packet(register: &Register, configs: &Context) -> Result<NaslValue,

let total_length = 20 + data.len();
let mut buf = vec![0; total_length];
let mut pkt = packet::ipv4::MutableIpv4Packet::new(&mut buf)
.ok_or_else(|| PacketForgeryError::CreatePacket)?;
let mut pkt =
packet::ipv4::MutableIpv4Packet::new(&mut buf).ok_or(PacketForgeryError::CreatePacket)?;

pkt.set_total_length(total_length as u16);

Expand Down Expand Up @@ -293,8 +293,8 @@ fn set_ip_elements(register: &Register, _configs: &Context) -> Result<NaslValue,
}
};

let mut pkt = packet::ipv4::MutableIpv4Packet::new(&mut buf)
.ok_or_else(|| PacketForgeryError::CreatePacket)?;
let mut pkt =
packet::ipv4::MutableIpv4Packet::new(&mut buf).ok_or(PacketForgeryError::CreatePacket)?;

let ip_hl = match register.named("ip_hl") {
Some(ContextType::Value(NaslValue::Number(x))) => *x as u8,
Expand Down Expand Up @@ -420,8 +420,8 @@ fn dump_ip_packet(register: &Register) -> Result<NaslValue, FnError> {
for ip in positional.iter() {
match ip {
NaslValue::Data(data) => {
let pkt = packet::ipv4::Ipv4Packet::new(data)
.ok_or_else(|| PacketForgeryError::CreatePacket)?;
let pkt =
packet::ipv4::Ipv4Packet::new(data).ok_or(PacketForgeryError::CreatePacket)?;

println!("\tip_hl={}", pkt.get_header_length());
println!("\tip_v={}", pkt.get_version());
Expand Down Expand Up @@ -1685,6 +1685,12 @@ fn dump_icmp_packet(register: &Register) -> Result<NaslValue, FnError> {
}

// IGMP
//
// Due to this line in libpnet, the #[packet] macro results in a clippy lint.
// The line just tries to allow another linting rule, so disabling the `unexpected_cfg` lint
// here should be reasonably safe.
// https://github.com/libpnet/libpnet/blob/a01aa493e2ecead4c45e7322b6c5f7ab29e8a985/pnet_macros/src/decorator.rs#L1138
#[allow(unexpected_cfgs)]
pub mod igmp {
use std::net::Ipv4Addr;

Expand Down Expand Up @@ -1821,7 +1827,7 @@ fn forge_igmp_packet(register: &Register, _configs: &Context) -> Result<NaslValu
ip_buf.append(&mut buf);
let l = ip_buf.len();
let mut pkt = packet::ipv4::MutableIpv4Packet::new(&mut ip_buf)
.ok_or_else(|| PacketForgeryError::CreatePacket)?;
.ok_or(PacketForgeryError::CreatePacket)?;
pkt.set_total_length(l as u16);
match register.named("update_ip_len") {
Some(ContextType::Value(NaslValue::Boolean(l))) if !(*l) => {
Expand Down Expand Up @@ -1872,7 +1878,7 @@ fn nasl_tcp_ping(register: &Register, configs: &Context) -> Result<NaslValue, Fn
}

let soc = new_raw_socket()?;
if let Err(e) = soc.set_header_included(true) {
if let Err(e) = soc.set_header_included_v4(true) {
return Err(error(format!("Not possible to create a raw socket: {}", e)));
};

Expand Down Expand Up @@ -2040,7 +2046,7 @@ fn nasl_send_packet(register: &Register, configs: &Context) -> Result<NaslValue,

let soc = new_raw_socket()?;

if let Err(e) = soc.set_header_included(true) {
if let Err(e) = soc.set_header_included_v4(true) {
return Err(error(format!("Not possible to create a raw socket: {}", e)));
};

Expand Down
4 changes: 2 additions & 2 deletions rust/src/nasl/builtin/ssh/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ fn userauth(t: &mut DefaultTestBuilder) {
#[tokio::test]
async fn ssh_userauth() {
run_test(
|mut t| {
|t| {
t.ok(
format!(r#"session_id = ssh_connect(port: {});"#, PORT),
MIN_SESSION_ID,
Expand Down Expand Up @@ -147,7 +147,7 @@ async fn ssh_userauth() {
#[cfg_attr(feature = "nasl-builtin-libssh", ignore)]
async fn ssh_request_exec() {
run_test(
|mut t| {
|t| {
t.ok(
format!(r#"session_id = ssh_connect(port: {});"#, PORT),
MIN_SESSION_ID,
Expand Down
2 changes: 1 addition & 1 deletion rust/src/nasl/interpreter/assign.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ impl Interpreter<'_> {
}
}

impl<'a> Interpreter<'a> {
impl Interpreter<'_> {
/// Assign a right value to a left value. Return either the
/// previous or the new value, based on the order.
pub async fn assign(
Expand Down
2 changes: 1 addition & 1 deletion rust/src/nasl/interpreter/call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use std::collections::HashMap;

use super::InterpretErrorKind;

impl<'a> Interpreter<'a> {
impl Interpreter<'_> {
pub async fn call(
&mut self,
statement: &Statement,
Expand Down
4 changes: 2 additions & 2 deletions rust/src/nasl/interpreter/interpreter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,10 @@ impl<'a> Interpreter<'a> {
Some(self)
}

async fn execute_statements<'b>(
async fn execute_statements(
&self,
key: &str,
inter: &mut Interpreter<'b>,
inter: &mut Interpreter<'_>,
stmt: Result<Statement, SyntaxError>,
) -> InterpretResult {
match stmt {
Expand Down
2 changes: 1 addition & 1 deletion rust/src/nasl/interpreter/loop_extension.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use super::interpreter::InterpretResult;

/// Note that for all loops, we do not
/// change the context, as the current NASL also does not change it too.
impl<'a> Interpreter<'a> {
impl Interpreter<'_> {
/// Interpreting a NASL for loop. A NASL for loop is built up with the
/// following:
///
Expand Down
4 changes: 2 additions & 2 deletions rust/src/nasl/interpreter/operator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use crate::nasl::interpreter::{error::InterpretError, interpreter::InterpretResu

use crate::nasl::syntax::NaslValue;

impl<'a> Interpreter<'a> {
impl Interpreter<'_> {
async fn execute(
&mut self,
stmts: &[Statement],
Expand Down Expand Up @@ -106,7 +106,7 @@ macro_rules! minus_left_right_data {
}};
}

impl<'a> Interpreter<'a> {
impl Interpreter<'_> {
/// Return the result of a NASL operator.
pub async fn operator(
&mut self,
Expand Down
20 changes: 4 additions & 16 deletions rust/src/notus/vts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,7 @@ where
full_name,
} => {
// Parse package from full name
let package = match P::from_full_name(full_name) {
Some(pkg) => pkg,
None => return None,
};
let package = P::from_full_name(full_name)?;
// Create Vulnerability Test Entry
Some((
package.get_name(),
Expand All @@ -147,10 +144,7 @@ where
name,
} => {
// Parse package from name and full version
let package = match P::from_name_and_full_version(name, full_version) {
Some(pkg) => pkg,
None => return None,
};
let package = P::from_name_and_full_version(name, full_version)?;
// Create Vulnerability Test Entry
Some((
package.get_name(),
Expand All @@ -165,14 +159,8 @@ where
}
FixedPackage::ByRange { range, name } => {
// Parse both packages from name and full version
let start = match P::from_name_and_full_version(name, &range.start) {
Some(pkg) => pkg,
None => return None,
};
let end = match P::from_name_and_full_version(name, &range.end) {
Some(pkg) => pkg,
None => return None,
};
let start = P::from_name_and_full_version(name, &range.start)?;
let end = P::from_name_and_full_version(name, &range.end)?;
// Create Vulnerability Test Entry
Some((
start.get_name(),
Expand Down
2 changes: 1 addition & 1 deletion rust/src/openvasd/controller/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ fn retrieve_and_reset(id: Arc<RwLock<ClientIdentifier>>) -> ClientIdentifier {
cci
}

pub async fn run<'a, S, DB>(
pub async fn run<S, DB>(
mut ctx: Context<S, DB>,
config: &config::Config,
) -> Result<(), Box<dyn std::error::Error + Send + Sync>>
Expand Down
2 changes: 1 addition & 1 deletion rust/src/openvasd/response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ impl Response {
return;
};
}
if value.map(|v| send(SendState::Bytes(false, v))).any(|x| x) {
if value.any(|v| send(SendState::Bytes(false, v))) {
return;
}

Expand Down
2 changes: 1 addition & 1 deletion rust/src/scanner/running_scan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ impl<S: ScannerStack> RunningScan<S> {
.map_err(make_scheduling_error)
}

async fn run_to_completion<'a>(&self, runner: ScanRunner<'a, S>) -> Phase {
async fn run_to_completion(&self, runner: ScanRunner<'_, S>) -> Phase {
let mut end_phase = Phase::Succeeded;
let mut stream = Box::pin(runner.stream());
while let Some(it) = stream.next().await {
Expand Down
7 changes: 4 additions & 3 deletions rust/src/scannerctl/osp/start_scan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@ pub struct Target {
pub credentials: Option<Credentials>,
}

impl Into<Vec<models::Credential>> for Credentials {
fn into(self) -> Vec<models::Credential> {
self.credential
impl From<Credentials> for Vec<models::Credential> {
fn from(other: Credentials) -> Self {
other
.credential
.into_iter()
.flatten()
.map(|x| {
Expand Down
8 changes: 4 additions & 4 deletions rust/src/scheduling/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,9 @@ pub trait ExecutionPlaner {
///
/// If the second value (parameter) is None it indicates that this script in indirectly loaded
/// and was not explicitly mentioned in the Scan.
fn execution_plan<'a, E>(
fn execution_plan<E>(
&self,
ids: &'a Scan,
ids: &Scan,
) -> Result<impl Iterator<Item = ConcurrentVTResult>, VTError>
where
E: ExecutionPlan;
Expand Down Expand Up @@ -208,9 +208,9 @@ impl<T> ExecutionPlaner for T
where
T: Retriever + ?Sized,
{
fn execution_plan<'a, E>(
fn execution_plan<E>(
&self,
scan: &'a Scan,
scan: &Scan,
) -> Result<impl Iterator<Item = ConcurrentVTResult>, VTError>
where
E: ExecutionPlan,
Expand Down

0 comments on commit 85b7559

Please sign in to comment.