detect/uint: wait for end of progress to match on all

As is done for absent keyword for instance
pull/13878/head
Philippe Antoine 1 year ago committed by Victor Julien
parent 5add185f22
commit dd81cfa733

@ -107,7 +107,7 @@ pub(crate) fn detect_parse_array_uint_enum<T1: DetectIntType, T2: EnumString<T1>
}
pub(crate) fn detect_uint_match_at_index<T, U: DetectIntType>(
array: &[T], ctx: &DetectUintArrayData<U>, get_value: impl Fn(&T) -> Option<U>,
array: &[T], ctx: &DetectUintArrayData<U>, get_value: impl Fn(&T) -> Option<U>, eof: bool,
) -> c_int {
match ctx.index {
DetectUintIndex::Any => {
@ -121,6 +121,9 @@ pub(crate) fn detect_uint_match_at_index<T, U: DetectIntType>(
return 0;
}
DetectUintIndex::All => {
if !eof {
return 0;
}
for response in array {
if let Some(code) = get_value(response) {
if !detect_match_uint::<U>(&ctx.du, code) {

@ -109,9 +109,12 @@ unsafe extern "C" fn dns_rrtype_match(
if flags & Direction::ToServer as u8 != 0 {
if let Some(request) = &tx.request {
return detect_uint_match_at_index::<DNSQueryEntry, u16>(&request.queries, ctx, |q| {
Some(q.rrtype)
});
return detect_uint_match_at_index::<DNSQueryEntry, u16>(
&request.queries,
ctx,
|q| Some(q.rrtype),
true,
);
}
} else if flags & Direction::ToClient as u8 != 0 {
if let Some(response) = &tx.response {
@ -119,6 +122,7 @@ unsafe extern "C" fn dns_rrtype_match(
&response.answers,
ctx,
|a| Some(a.rrtype),
true,
);
}
}

@ -151,8 +151,8 @@ fn http2_match_priority(
} else {
&tx.frames_tc
};
return detect_uint_match_at_index::<HTTP2Frame, u8>(frames, ctx, get_http2_priority);
let eof = tx.state >= HTTP2TransactionState::HTTP2StateClosed;
return detect_uint_match_at_index::<HTTP2Frame, u8>(frames, ctx, get_http2_priority, eof);
}
#[no_mangle]
@ -179,7 +179,8 @@ fn http2_match_window(
} else {
&tx.frames_tc
};
return detect_uint_match_at_index::<HTTP2Frame, u32>(frames, ctx, get_http2_window);
let eof = tx.state >= HTTP2TransactionState::HTTP2StateClosed;
return detect_uint_match_at_index::<HTTP2Frame, u32>(frames, ctx, get_http2_window, eof);
}
#[no_mangle]

@ -151,9 +151,12 @@ unsafe extern "C" fn ldap_detect_responses_operation_match(
let tx = cast_pointer!(tx, LdapTransaction);
let ctx = cast_pointer!(ctx, DetectUintArrayData<u8>);
return detect_uint_match_at_index::<LdapMessage, u8>(&tx.responses, ctx, |response| {
Some(response.protocol_op.tag().0 as u8)
});
return detect_uint_match_at_index::<LdapMessage, u8>(
&tx.responses,
ctx,
|response| Some(response.protocol_op.tag().0 as u8),
tx.complete,
);
}
unsafe extern "C" fn ldap_detect_responses_free(_de: *mut DetectEngineCtx, ctx: *mut c_void) {
@ -350,6 +353,7 @@ unsafe extern "C" fn ldap_detect_responses_result_code_match(
&tx.responses,
ctx,
get_ldap_result_code,
tx.complete,
);
}

@ -65,7 +65,7 @@ pub struct LdapTransaction {
pub tx_id: u64,
pub request: Option<LdapMessage<'static>>,
pub responses: Vec<LdapMessage<'static>>,
complete: bool,
pub complete: bool,
tx_data: AppLayerTxData,
}

@ -45,9 +45,12 @@ use std::ptr;
use std::str::FromStr;
fn mqtt_tx_has_type(tx: &MQTTTransaction, ctx: &DetectUintArrayData<u8>) -> c_int {
return detect_uint_match_at_index::<MQTTMessage, u8>(&tx.msg, ctx, |msg| {
Some(msg.header.message_type as u8)
});
return detect_uint_match_at_index::<MQTTMessage, u8>(
&tx.msg,
ctx,
|msg| Some(msg.header.message_type as u8),
tx.complete,
);
}
unsafe extern "C" fn mqtt_conn_clientid_get_data(

@ -75,7 +75,7 @@ pub struct MQTTTransaction {
tx_id: u64,
pkt_id: Option<u32>,
pub msg: Vec<MQTTMessage>,
complete: bool,
pub complete: bool,
toclient: bool,
toserver: bool,

Loading…
Cancel
Save