@ -1,4 +1,4 @@
/* Copyright (C) 2007-202 2 Open Information Security Foundation
/* Copyright (C) 2007-202 5 Open Information Security Foundation
*
* You can copy , redistribute or modify this Program under the terms of
* the GNU General Public License version 2 as published by the Free
@ -630,6 +630,70 @@ int DetectFlowbitsAnalyze(DetectEngineCtx *de_ctx)
SCLogDebug ( " GET flowbit %s/%u: SID %u " , varname , i , s - > id ) ;
s - > init_data - > init_flags | = SIG_FLAG_INIT_STATE_MATCH ;
s - > init_data - > is_rule_state_dependant = true ;
uint32_t sids_array_size = array [ i ] . set_sids_idx ;
// save information about flowbits that affect this rule's state
if ( s - > init_data - > rule_state_dependant_sids_array = = NULL ) {
s - > init_data - > rule_state_dependant_sids_array =
SCCalloc ( sids_array_size , sizeof ( uint32_t ) ) ;
if ( s - > init_data - > rule_state_dependant_sids_array = = NULL ) {
SCLogError ( " Failed to allocate memory for rule_state_dependant_ids " ) ;
goto end ;
}
s - > init_data - > rule_state_flowbits_ids_size = 1 ;
s - > init_data - > rule_state_flowbits_ids_array =
SCCalloc ( s - > init_data - > rule_state_flowbits_ids_size , sizeof ( uint32_t ) ) ;
if ( s - > init_data - > rule_state_flowbits_ids_array = = NULL ) {
SCLogError ( " Failed to allocate memory for rule_state_variable_idx " ) ;
goto end ;
}
s - > init_data - > rule_state_dependant_sids_size = sids_array_size ;
SCLogDebug ( " alloc'ed array for rule dependency and fbs idx array, sid %u, "
" sizes are %u and %u " ,
s - > id , s - > init_data - > rule_state_dependant_sids_size ,
s - > init_data - > rule_state_flowbits_ids_size ) ;
} else {
uint32_t new_array_size =
s - > init_data - > rule_state_dependant_sids_size + sids_array_size ;
void * tmp_ptr = SCRealloc ( s - > init_data - > rule_state_dependant_sids_array ,
new_array_size * sizeof ( uint32_t ) ) ;
if ( tmp_ptr = = NULL ) {
SCLogError ( " Failed to allocate memory for rule_state_variable_idx " ) ;
goto end ;
}
s - > init_data - > rule_state_dependant_sids_array = tmp_ptr ;
s - > init_data - > rule_state_dependant_sids_size = new_array_size ;
SCLogDebug ( " realloc'ed array for rule dependency, sid %u, new size is %u " ,
s - > id , s - > init_data - > rule_state_dependant_sids_size ) ;
uint32_t new_fb_array_size = s - > init_data - > rule_state_flowbits_ids_size + 1 ;
void * tmp_fb_ptr = SCRealloc ( s - > init_data - > rule_state_flowbits_ids_array ,
new_fb_array_size * sizeof ( uint32_t ) ) ;
s - > init_data - > rule_state_flowbits_ids_array = tmp_fb_ptr ;
if ( s - > init_data - > rule_state_flowbits_ids_array = = NULL ) {
SCLogError ( " Failed to reallocate memory for rule_state_variable_idx " ) ;
goto end ;
}
SCLogDebug (
" realloc'ed array for flowbits ids, new size is %u " , new_fb_array_size ) ;
s - > init_data - > rule_state_dependant_sids_size = new_array_size ;
s - > init_data - > rule_state_flowbits_ids_size = new_fb_array_size ;
}
for ( uint32_t idx = 0 ; idx < s - > init_data - > rule_state_dependant_sids_size ; idx + + ) {
if ( idx < array [ i ] . set_sids_idx ) {
s - > init_data - > rule_state_dependant_sids_array
[ s - > init_data - > rule_state_dependant_sids_idx ] =
de_ctx - > sig_array [ array [ i ] . set_sids [ idx ] ] - > id ;
s - > init_data - > rule_state_dependant_sids_idx + + ;
}
}
s - > init_data
- > rule_state_flowbits_ids_array [ s - > init_data - > rule_state_flowbits_ids_size -
1 ] = i ;
s - > init_data - > rule_state_flowbits_ids_size + = 1 ;
// flowbit info saving for rule made stateful rule work finished
SCLogDebug ( " made SID %u stateful because it depends on "
" stateful rules that set flowbit %s " , s - > id , varname ) ;
}