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

applayer/ftp: Post-merge fixups #12687

Merged
merged 3 commits into from
Feb 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
10 changes: 10 additions & 0 deletions rust/src/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
//! This module exposes items from the core "C" code to Rust.

use std;
use std::os::raw::{c_int, c_void};
use suricata_sys::sys::{AppProto, AppProtoEnum};

use crate::filecontainer::*;
Expand Down Expand Up @@ -72,6 +73,15 @@ extern {
pub fn StringToAppProto(proto_name: *const u8) -> AppProto;
}

/// cbindgen:ignore
extern "C" {
pub fn MpmAddPatternCI(
ctx: *const c_void, pat: *const libc::c_char, pat_len: c_int, _offset: c_int,
_depth: c_int, id: c_int, rule_id: c_int, _flags: c_int,
) -> c_void;
}


//
// Function types for calls into C.
//
Expand Down
4 changes: 2 additions & 2 deletions rust/src/ftp/constant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ pub enum FtpStateValues {
#[repr(u8)]
#[allow(non_camel_case_types)]
pub enum FtpDataStateValues {
FTPDATA_STATE_IN_PROGRESS = 1,
FTPDATA_STATE_FINISHED = 2,
FTPDATA_STATE_IN_PROGRESS,
FTPDATA_STATE_FINISHED,
}

// FTP request command values
Expand Down
12 changes: 2 additions & 10 deletions rust/src/ftp/ftp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ use std;
use std::ffi::CString;
use std::os::raw::{c_char, c_int, c_void};

use crate::core::*;
use crate::conf::{conf_get, get_memval};
use crate::ftp::constant::*;
use lazy_static::lazy_static;
Expand Down Expand Up @@ -97,14 +98,6 @@ lazy_static! {
];
}

/// cbindgen:ignore
extern "C" {
pub fn MpmAddPatternCI(
ctx: *const c_void, pat: *const libc::c_char, pat_len: c_int, _offset: c_int,
_depth: c_int, id: c_int, rule_id: c_int, _flags: c_int,
) -> c_void;
}

#[allow(non_snake_case)]
#[no_mangle]
pub unsafe extern "C" fn SCGetFtpCommandInfo(
Expand Down Expand Up @@ -150,7 +143,6 @@ pub unsafe extern "C" fn SCFTPSetMpmState(ctx: *const c_void) {
}

#[repr(C)]
#[allow(dead_code)]
pub struct FtpTransferCmd {
// Must be first -- required by app-layer expectation logic
data_free: unsafe extern "C" fn(*mut c_void),
Expand All @@ -168,7 +160,7 @@ impl Default for FtpTransferCmd {
file_name: std::ptr::null_mut(),
file_len: 0,
direction: 0,
cmd: FtpStateValues::FTP_STATE_NONE as u8,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is this changed? It seems a named value is clearer

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's an incorrect value -- it's expected to be a command enum ... not a state value

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should it be FTP_COMMAND_UNKNOWN then?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe? It's always initialized before use -- the current code calloc's the memory for this struct which is why I used 0

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok lets leave as-is

cmd: 0,
data_free: default_free_fn,
}
}
Expand Down
Loading