Skip to content

Commit

Permalink
Fix remaining linter warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
timokoessler committed Jan 27, 2025
1 parent eb7c4d9 commit 23c6d73
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 12 deletions.
9 changes: 9 additions & 0 deletions src/ffi_bindings/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ use std::os::raw::{c_char, c_int};
use std::panic;
use std::str;

/// # Safety
///
/// This function should only be called with valid pointers to C strings.
#[no_mangle]
pub unsafe extern "C" fn detect_shell_injection(
command: *const c_char,
Expand Down Expand Up @@ -33,6 +36,9 @@ pub unsafe extern "C" fn detect_shell_injection(
.unwrap_or(2)
}

/// # Safety
///
/// This function should only be called with valid pointers to C strings.
#[no_mangle]
pub unsafe extern "C" fn detect_sql_injection(
query: *const c_char,
Expand Down Expand Up @@ -61,6 +67,9 @@ pub unsafe extern "C" fn detect_sql_injection(
.unwrap_or(2)
}

/// # Safety
///
/// This function should only be called with valid pointers to C strings.
#[no_mangle]
pub unsafe extern "C" fn detect_js_injection(
code: *const c_char,
Expand Down
8 changes: 4 additions & 4 deletions src/shell_injection/contains_shell_syntax.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,18 +154,18 @@ pub fn contains_shell_syntax(command: &str, user_input: &str) -> bool {
};

// Check surrounding characters
if char_before.map_or(false, |c| SEPARATORS.contains(&c.to_string().as_str()))
&& char_after.map_or(false, |c| SEPARATORS.contains(&c.to_string().as_str()))
if char_before.is_some_and(|c| SEPARATORS.contains(&c.to_string().as_str()))
&& char_after.is_some_and(|c| SEPARATORS.contains(&c.to_string().as_str()))
{
return true; // e.g. `<separator>rm<separator>`
}
if char_before.map_or(false, |c| SEPARATORS.contains(&c.to_string().as_str()))
if char_before.is_some_and(|c| SEPARATORS.contains(&c.to_string().as_str()))
&& char_after.is_none()
{
return true; // e.g. `<separator>rm`
}
if char_before.is_none()
&& char_after.map_or(false, |c| SEPARATORS.contains(&c.to_string().as_str()))
&& char_after.is_some_and(|c| SEPARATORS.contains(&c.to_string().as_str()))
{
return true; // e.g. `rm<separator>`
}
Expand Down
6 changes: 3 additions & 3 deletions src/shell_injection/is_safely_encapsulated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ pub fn is_safely_encapsulated(command: &str, user_input: &str) -> bool {
let char_before_user_input = current_segment.chars().last();
let char_after_user_input = next_segment.chars().next();

let is_escape_char = char_before_user_input
.map_or(false, |c| ESCAPE_CHARS.contains(&c.to_string().as_str()));
let is_escape_char =
char_before_user_input.is_some_and(|c| ESCAPE_CHARS.contains(&c.to_string().as_str()));

if !is_escape_char {
return false;
Expand All @@ -35,7 +35,7 @@ pub fn is_safely_encapsulated(command: &str, user_input: &str) -> bool {
return false;
}

if char_before_user_input.map_or(false, |c| user_input.contains(c)) {
if char_before_user_input.is_some_and(|c| user_input.contains(c)) {
return false;
}

Expand Down
10 changes: 5 additions & 5 deletions src/sql_injection/filter_for_comment_tokens.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ pub fn filter_for_comment_tokens(tokens: Vec<Token>) -> Vec<Whitespace> {
if let Token::Whitespace(whitespace) = token {
// Token is whitespace, if this token is singleline comment or multiline,
// Add to comments_vector.
let whitespace_is_comment = match whitespace {
Whitespace::SingleLineComment { .. } => true,
Whitespace::MultiLineComment(_) => true,
_ => false,
};
let whitespace_is_comment = matches!(
whitespace,
Whitespace::SingleLineComment { .. } | Whitespace::MultiLineComment(_)
);

if whitespace_is_comment {
comments_vector.push(whitespace);
}
Expand Down

0 comments on commit 23c6d73

Please sign in to comment.