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

Next/20210823/v4 #6304

Merged
merged 24 commits into from
Aug 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
09ea412
util-debug: fix unchecked ConfGetBool call
jufajardini Aug 10, 2021
fbade25
util-napatech: fix ConfGetBool unchecked call
jufajardini Aug 10, 2021
7198355
util-napatech: fix typos, update copyright year
jufajardini Aug 10, 2021
4839088
stream-tcp: fix ConfGetBool unchecked call
jufajardini Aug 10, 2021
2e0d76e
stream-tcp: fix typos, update copyright year
jufajardini Aug 10, 2021
613f9b2
stream-tcp-reassemble: fix ConfGetBool unc'kd call
jufajardini Aug 10, 2021
ff976df
stream-tcp-reassemble: fix typo, updt copyright yr
jufajardini Aug 10, 2021
7ca4b13
qa: use time on fuzz targets being run on corpus
catenacyber Jul 22, 2021
cbd03c7
output/redis: Fix possible segv
KevinWL Aug 6, 2021
53413f2
rust: remove all usage of transmute
jasonish Jul 26, 2021
363b5f9
rust: functions that reference raw pointers are unsafe
jasonish Jul 26, 2021
69cf5c9
rust(lint): remove needless borrows
jasonish Aug 20, 2021
602bb05
rust(lint): fix redundant closures
jasonish Aug 20, 2021
5bf5de3
rust(lint): don't use unwrap_or for function calls
jasonish Aug 20, 2021
8bb6dab
rust(lint): remove useless format calls
jasonish Aug 20, 2021
ac3a20b
rust(lint): remove useless conversions and clones
jasonish Aug 20, 2021
4abbfd0
rust(lint): remove extra parens around bitwise or
jasonish Aug 20, 2021
d0be754
rust(lint): removed unused unit () return
jasonish Aug 20, 2021
d0772e0
rust(lint): replace checked_mul with saturating_mul
jasonish Aug 20, 2021
d5c0962
rust(lint): fix some usages of references
jasonish Aug 20, 2021
dcf57ec
rust(lint): replace push_str of single char to push(<char>)
jasonish Aug 20, 2021
b021726
rust(lint): map the error instead of using or_else
jasonish Aug 20, 2021
91402f9
rust(lint): remove manual implement of map method
jasonish Aug 20, 2021
cf21694
rust(lint): suppress clippy lints that we should fix
jasonish Aug 20, 2021
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
1 change: 1 addition & 0 deletions .github/workflows/builds.yml
Original file line number Diff line number Diff line change
Expand Up @@ -741,6 +741,7 @@ jobs:
exuberant-ctags \
unzip \
curl \
time \
wget
- uses: actions/checkout@v2
- uses: actions/download-artifact@v2
Expand Down
2 changes: 1 addition & 1 deletion qa/run-ossfuzz-corpus.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ do
rm -rf corpus_$target
unzip -q public.zip -d corpus_$target
#run target on corpus.
./src/$target corpus_$target
/usr/bin/time -v ./src/$target corpus_$target
done
39 changes: 20 additions & 19 deletions rust/src/applayer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,40 +238,41 @@ pub struct RustParser {
/// UNSAFE !
#[macro_export]
macro_rules! build_slice {
($buf:ident, $len:expr) => ( unsafe{ std::slice::from_raw_parts($buf, $len) } );
($buf:ident, $len:expr) => ( std::slice::from_raw_parts($buf, $len) );
}

/// Cast pointer to a variable, as a mutable reference to an object
///
/// UNSAFE !
#[macro_export]
macro_rules! cast_pointer {
($ptr:ident, $ty:ty) => ( unsafe{ &mut *($ptr as *mut $ty) } );
($ptr:ident, $ty:ty) => ( &mut *($ptr as *mut $ty) );
}

pub type ParseFn = extern "C" fn (flow: *const Flow,
pub type ParseFn = unsafe extern "C" fn (flow: *const Flow,
state: *mut c_void,
pstate: *mut c_void,
input: *const u8,
input_len: u32,
data: *const c_void,
flags: u8) -> AppLayerResult;
pub type ProbeFn = extern "C" fn (flow: *const Flow, flags: u8, input:*const u8, input_len: u32, rdir: *mut u8) -> AppProto;
pub type ProbeFn = unsafe extern "C" fn (flow: *const Flow, flags: u8, input:*const u8, input_len: u32, rdir: *mut u8) -> AppProto;
pub type StateAllocFn = extern "C" fn (*mut c_void, AppProto) -> *mut c_void;
pub type StateFreeFn = extern "C" fn (*mut c_void);
pub type StateTxFreeFn = extern "C" fn (*mut c_void, u64);
pub type StateGetTxFn = extern "C" fn (*mut c_void, u64) -> *mut c_void;
pub type StateGetTxCntFn = extern "C" fn (*mut c_void) -> u64;
pub type StateGetProgressFn = extern "C" fn (*mut c_void, u8) -> c_int;
pub type GetDetectStateFn = extern "C" fn (*mut c_void) -> *mut DetectEngineState;
pub type SetDetectStateFn = extern "C" fn (*mut c_void, &mut DetectEngineState) -> c_int;
pub type GetEventInfoFn = extern "C" fn (*const c_char, *mut c_int, *mut AppLayerEventType) -> c_int;
pub type GetEventInfoByIdFn = extern "C" fn (c_int, *mut *const c_char, *mut AppLayerEventType) -> i8;
pub type GetEventsFn = extern "C" fn (*mut c_void) -> *mut AppLayerDecoderEvents;
pub type StateFreeFn = unsafe extern "C" fn (*mut c_void);
pub type StateTxFreeFn = unsafe extern "C" fn (*mut c_void, u64);
pub type StateGetTxFn = unsafe extern "C" fn (*mut c_void, u64) -> *mut c_void;
pub type StateGetTxCntFn = unsafe extern "C" fn (*mut c_void) -> u64;
pub type StateGetProgressFn = unsafe extern "C" fn (*mut c_void, u8) -> c_int;
pub type GetDetectStateFn = unsafe extern "C" fn (*mut c_void) -> *mut DetectEngineState;
pub type SetDetectStateFn = unsafe extern "C" fn (*mut c_void, &mut DetectEngineState) -> c_int;
pub type GetEventInfoFn = unsafe extern "C" fn (*const c_char, *mut c_int, *mut AppLayerEventType) -> c_int;
pub type GetEventInfoByIdFn = unsafe extern "C" fn (c_int, *mut *const c_char, *mut AppLayerEventType) -> i8;
pub type GetEventsFn = unsafe extern "C" fn (*mut c_void) -> *mut AppLayerDecoderEvents;
pub type LocalStorageNewFn = extern "C" fn () -> *mut c_void;
pub type LocalStorageFreeFn = extern "C" fn (*mut c_void);
pub type GetFilesFn = extern "C" fn (*mut c_void, u8) -> *mut FileContainer;
pub type GetTxIteratorFn = extern "C" fn (ipproto: u8, alproto: AppProto,
pub type GetFilesFn = unsafe
extern "C" fn (*mut c_void, u8) -> *mut FileContainer;
pub type GetTxIteratorFn = unsafe extern "C" fn (ipproto: u8, alproto: AppProto,
state: *mut c_void,
min_tx_id: u64,
max_tx_id: u64,
Expand Down Expand Up @@ -320,7 +321,7 @@ pub const APP_LAYER_PARSER_BYPASS_READY : u8 = BIT_U8!(4);
pub const APP_LAYER_PARSER_OPT_ACCEPT_GAPS: u32 = BIT_U32!(0);
pub const APP_LAYER_PARSER_OPT_UNIDIR_TXS: u32 = BIT_U32!(1);

pub type AppLayerGetTxIteratorFn = extern "C" fn (ipproto: u8,
pub type AppLayerGetTxIteratorFn = unsafe extern "C" fn (ipproto: u8,
alproto: AppProto,
alstate: *mut c_void,
min_tx_id: u64,
Expand Down Expand Up @@ -384,7 +385,7 @@ impl LoggerFlags {
macro_rules!export_tx_get_detect_state {
($name:ident, $type:ty) => (
#[no_mangle]
pub extern "C" fn $name(tx: *mut std::os::raw::c_void)
pub unsafe extern "C" fn $name(tx: *mut std::os::raw::c_void)
-> *mut core::DetectEngineState
{
let tx = cast_pointer!(tx, $type);
Expand All @@ -405,7 +406,7 @@ macro_rules!export_tx_get_detect_state {
macro_rules!export_tx_set_detect_state {
($name:ident, $type:ty) => (
#[no_mangle]
pub extern "C" fn $name(tx: *mut std::os::raw::c_void,
pub unsafe extern "C" fn $name(tx: *mut std::os::raw::c_void,
de_state: &mut core::DetectEngineState) -> std::os::raw::c_int
{
let tx = cast_pointer!(tx, $type);
Expand Down
2 changes: 1 addition & 1 deletion rust/src/applayertemplate/logger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ fn log_template(tx: &TemplateTransaction, js: &mut JsonBuilder) -> Result<(), Js
}

#[no_mangle]
pub extern "C" fn rs_template_logger_log(tx: *mut std::os::raw::c_void, js: &mut JsonBuilder) -> bool {
pub unsafe extern "C" fn rs_template_logger_log(tx: *mut std::os::raw::c_void, js: &mut JsonBuilder) -> bool {
let tx = cast_pointer!(tx, TemplateTransaction);
log_template(tx, js).is_ok()
}
70 changes: 30 additions & 40 deletions rust/src/applayertemplate/template.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

use std;
use crate::core::{self, ALPROTO_UNKNOWN, AppProto, Flow, IPPROTO_TCP};
use std::mem::transmute;
use crate::applayer::{self, *};
use std::ffi::CString;
use nom;
Expand Down Expand Up @@ -277,7 +276,7 @@ export_tx_set_detect_state!(

/// C entry point for a probing parser.
#[no_mangle]
pub extern "C" fn rs_template_probing_parser(
pub unsafe extern "C" fn rs_template_probing_parser(
_flow: *const Flow,
_direction: u8,
input: *const u8,
Expand All @@ -288,7 +287,7 @@ pub extern "C" fn rs_template_probing_parser(
if input_len > 1 && input != std::ptr::null_mut() {
let slice = build_slice!(input, input_len as usize);
if probe(slice).is_ok() {
return unsafe { ALPROTO_TEMPLATE };
return ALPROTO_TEMPLATE;
}
}
return ALPROTO_UNKNOWN;
Expand All @@ -298,17 +297,16 @@ pub extern "C" fn rs_template_probing_parser(
pub extern "C" fn rs_template_state_new(_orig_state: *mut std::os::raw::c_void, _orig_proto: AppProto) -> *mut std::os::raw::c_void {
let state = TemplateState::new();
let boxed = Box::new(state);
return unsafe { transmute(boxed) };
return Box::into_raw(boxed) as *mut std::os::raw::c_void;
}

#[no_mangle]
pub extern "C" fn rs_template_state_free(state: *mut std::os::raw::c_void) {
// Just unbox...
let _drop: Box<TemplateState> = unsafe { transmute(state) };
pub unsafe extern "C" fn rs_template_state_free(state: *mut std::os::raw::c_void) {
std::mem::drop(Box::from_raw(state as *mut TemplateState));
}

#[no_mangle]
pub extern "C" fn rs_template_state_tx_free(
pub unsafe extern "C" fn rs_template_state_tx_free(
state: *mut std::os::raw::c_void,
tx_id: u64,
) {
Expand All @@ -317,7 +315,7 @@ pub extern "C" fn rs_template_state_tx_free(
}

#[no_mangle]
pub extern "C" fn rs_template_parse_request(
pub unsafe extern "C" fn rs_template_parse_request(
_flow: *const Flow,
state: *mut std::os::raw::c_void,
pstate: *mut std::os::raw::c_void,
Expand All @@ -326,12 +324,10 @@ pub extern "C" fn rs_template_parse_request(
_data: *const std::os::raw::c_void,
_flags: u8,
) -> AppLayerResult {
let eof = unsafe {
if AppLayerParserStateIssetFlag(pstate, APP_LAYER_PARSER_EOF_TS) > 0 {
true
} else {
false
}
let eof = if AppLayerParserStateIssetFlag(pstate, APP_LAYER_PARSER_EOF_TS) > 0 {
true
} else {
false
};

if eof {
Expand All @@ -353,7 +349,7 @@ pub extern "C" fn rs_template_parse_request(
}

#[no_mangle]
pub extern "C" fn rs_template_parse_response(
pub unsafe extern "C" fn rs_template_parse_response(
_flow: *const Flow,
state: *mut std::os::raw::c_void,
pstate: *mut std::os::raw::c_void,
Expand All @@ -362,12 +358,10 @@ pub extern "C" fn rs_template_parse_response(
_data: *const std::os::raw::c_void,
_flags: u8,
) -> AppLayerResult {
let _eof = unsafe {
if AppLayerParserStateIssetFlag(pstate, APP_LAYER_PARSER_EOF_TC) > 0 {
true
} else {
false
}
let _eof = if AppLayerParserStateIssetFlag(pstate, APP_LAYER_PARSER_EOF_TC) > 0 {
true
} else {
false
};
let state = cast_pointer!(state, TemplateState);

Expand All @@ -378,19 +372,19 @@ pub extern "C" fn rs_template_parse_response(
AppLayerResult::ok()
} else {
let buf = build_slice!(input, input_len as usize);
state.parse_response(buf).into()
state.parse_response(buf)
}
}

#[no_mangle]
pub extern "C" fn rs_template_state_get_tx(
pub unsafe extern "C" fn rs_template_state_get_tx(
state: *mut std::os::raw::c_void,
tx_id: u64,
) -> *mut std::os::raw::c_void {
let state = cast_pointer!(state, TemplateState);
match state.get_tx(tx_id) {
Some(tx) => {
return unsafe { transmute(tx) };
return tx as *const _ as *mut _;
}
None => {
return std::ptr::null_mut();
Expand All @@ -399,15 +393,15 @@ pub extern "C" fn rs_template_state_get_tx(
}

#[no_mangle]
pub extern "C" fn rs_template_state_get_tx_count(
pub unsafe extern "C" fn rs_template_state_get_tx_count(
state: *mut std::os::raw::c_void,
) -> u64 {
let state = cast_pointer!(state, TemplateState);
return state.tx_id;
}

#[no_mangle]
pub extern "C" fn rs_template_tx_get_alstate_progress(
pub unsafe extern "C" fn rs_template_tx_get_alstate_progress(
tx: *mut std::os::raw::c_void,
_direction: u8,
) -> std::os::raw::c_int {
Expand All @@ -421,7 +415,7 @@ pub extern "C" fn rs_template_tx_get_alstate_progress(
}

#[no_mangle]
pub extern "C" fn rs_template_state_get_events(
pub unsafe extern "C" fn rs_template_state_get_events(
tx: *mut std::os::raw::c_void
) -> *mut core::AppLayerDecoderEvents {
let tx = cast_pointer!(tx, TemplateTransaction);
Expand All @@ -445,7 +439,7 @@ pub extern "C" fn rs_template_state_get_event_info_by_id(_event_id: std::os::raw
return -1;
}
#[no_mangle]
pub extern "C" fn rs_template_state_get_tx_iterator(
pub unsafe extern "C" fn rs_template_state_get_tx_iterator(
_ipproto: u8,
_alproto: AppProto,
state: *mut std::os::raw::c_void,
Expand All @@ -456,7 +450,7 @@ pub extern "C" fn rs_template_state_get_tx_iterator(
let state = cast_pointer!(state, TemplateState);
match state.tx_iterator(min_tx_id, istate) {
Some((tx, out_tx_id, has_next)) => {
let c_tx = unsafe { transmute(tx) };
let c_tx = tx as *const _ as *mut _;
let ires = applayer::AppLayerGetTxIterTuple::with_values(
c_tx,
out_tx_id,
Expand All @@ -475,7 +469,7 @@ pub extern "C" fn rs_template_state_get_tx_iterator(
/// No required for parsing, but an example function for retrieving a
/// pointer to the request buffer from C for detection.
#[no_mangle]
pub extern "C" fn rs_template_get_request_buffer(
pub unsafe extern "C" fn rs_template_get_request_buffer(
tx: *mut std::os::raw::c_void,
buf: *mut *const u8,
len: *mut u32,
Expand All @@ -484,10 +478,8 @@ pub extern "C" fn rs_template_get_request_buffer(
let tx = cast_pointer!(tx, TemplateTransaction);
if let Some(ref request) = tx.request {
if request.len() > 0 {
unsafe {
*len = request.len() as u32;
*buf = request.as_ptr();
}
*len = request.len() as u32;
*buf = request.as_ptr();
return 1;
}
}
Expand All @@ -496,7 +488,7 @@ pub extern "C" fn rs_template_get_request_buffer(

/// Get the response buffer for a transaction from C.
#[no_mangle]
pub extern "C" fn rs_template_get_response_buffer(
pub unsafe extern "C" fn rs_template_get_response_buffer(
tx: *mut std::os::raw::c_void,
buf: *mut *const u8,
len: *mut u32,
Expand All @@ -505,10 +497,8 @@ pub extern "C" fn rs_template_get_response_buffer(
let tx = cast_pointer!(tx, TemplateTransaction);
if let Some(ref response) = tx.response {
if response.len() > 0 {
unsafe {
*len = response.len() as u32;
*buf = response.as_ptr();
}
*len = response.len() as u32;
*buf = response.as_ptr();
return 1;
}
}
Expand Down
6 changes: 3 additions & 3 deletions rust/src/asn1/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ impl<'a> Asn1<'a> {
{
if let BerObjectContent::BitString(bits, _v) = &obj.content {
if obj.header.len > 0
&& *bits as u64 > (obj.header.len.checked_mul(8).unwrap_or(std::u64::MAX))
&& *bits as u64 > obj.header.len.saturating_mul(8)
{
return Some(Asn1Check::BitstringOverflow);
}
Expand Down Expand Up @@ -211,7 +211,7 @@ fn asn1_decode<'a>(
/// input must be a valid buffer of at least input_len bytes
/// pointer must be freed using `rs_asn1_free`
#[no_mangle]
pub extern "C" fn rs_asn1_decode(
pub unsafe extern "C" fn rs_asn1_decode(
input: *const u8, input_len: u16, buffer_offset: u32, ad_ptr: *const DetectAsn1Data,
) -> *mut Asn1<'static> {
if input.is_null() || input_len == 0 || ad_ptr.is_null() {
Expand All @@ -220,7 +220,7 @@ pub extern "C" fn rs_asn1_decode(

let slice = build_slice!(input, input_len as usize);

let ad = unsafe { &*ad_ptr };
let ad = &*ad_ptr ;

let res = asn1_decode(slice, buffer_offset, ad);

Expand Down
2 changes: 1 addition & 1 deletion rust/src/asn1/parse_rules.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ pub unsafe extern "C" fn rs_detect_asn1_parse(input: *const c_char) -> *mut Dete
}
};

match asn1_parse_rule(&arg) {
match asn1_parse_rule(arg) {
Ok((_rest, data)) => {
let mut data = data;

Expand Down
Loading