@@ -312,11 +312,7 @@ pub struct DCERPCState {
312
312
tx_index_completed : usize ,
313
313
pub pad : u8 ,
314
314
pub padleft : u16 ,
315
- pub bytes_consumed : i32 ,
316
315
pub tx_id : u64 ,
317
- pub query_completed : bool ,
318
- pub data_needed_for_dir : Direction ,
319
- pub prev_dir : Direction ,
320
316
pub ts_gap : bool ,
321
317
pub tc_gap : bool ,
322
318
pub ts_ssn_gap : bool ,
@@ -338,8 +334,6 @@ impl State<DCERPCTransaction> for DCERPCState {
338
334
impl DCERPCState {
339
335
pub fn new ( ) -> Self {
340
336
return Self {
341
- data_needed_for_dir : Direction :: ToServer ,
342
- prev_dir : Direction :: ToServer ,
343
337
..Default :: default ( )
344
338
}
345
339
}
@@ -444,26 +438,6 @@ impl DCERPCState {
444
438
None
445
439
}
446
440
447
- pub fn clean_buffer ( & mut self , direction : Direction ) {
448
- match direction {
449
- Direction :: ToServer => {
450
- self . ts_gap = false ;
451
- }
452
- Direction :: ToClient => {
453
- self . tc_gap = false ;
454
- }
455
- }
456
- self . bytes_consumed = 0 ;
457
- }
458
-
459
- pub fn reset_direction ( & mut self , direction : Direction ) {
460
- if direction == Direction :: ToServer {
461
- self . data_needed_for_dir = Direction :: ToClient ;
462
- } else {
463
- self . data_needed_for_dir = Direction :: ToServer ;
464
- }
465
- }
466
-
467
441
/// Get transaction as per the given transaction ID. Transaction ID with
468
442
/// which the lookup is supposed to be done as per the calls from AppLayer
469
443
/// parser in C. This requires an internal transaction ID to be maintained.
@@ -901,9 +875,6 @@ impl DCERPCState {
901
875
let mut parsed = 0 ;
902
876
let retval;
903
877
let mut cur_i = input;
904
- let mut input_len = cur_i. len ( ) ;
905
- // Set any query's completion status to false in the beginning
906
- self . query_completed = false ;
907
878
908
879
// Skip the record since this means that its in the middle of a known length record
909
880
if ( self . ts_gap && direction == Direction :: ToServer ) || ( self . tc_gap && direction == Direction :: ToClient ) {
@@ -936,40 +907,26 @@ impl DCERPCState {
936
907
}
937
908
}
938
909
939
- // Overwrite the dcerpc_state data in case of multiple complete queries in the
940
- // same direction
941
- if self . prev_dir == direction {
942
- self . data_needed_for_dir = direction;
943
- }
944
-
945
- if self . data_needed_for_dir != direction && !cur_i. is_empty ( ) {
946
- return AppLayerResult :: err ( ) ;
947
- }
948
-
949
- // Set data_needed_for_dir in the same direction in case there is an issue with upcoming parsing
950
- self . data_needed_for_dir = direction;
951
-
910
+ let mut frag_bytes_consumed: u16 = 0 ;
952
911
// Check if header data was complete. In case of EoF or incomplete data, wait for more
953
912
// data else return error
954
- if self . header . is_none ( ) && input_len > 0 {
913
+ if self . header . is_none ( ) && !cur_i . is_empty ( ) {
955
914
parsed = self . process_header ( cur_i) ;
956
915
if parsed == -1 {
957
916
return AppLayerResult :: incomplete ( 0 , DCERPC_HDR_LEN as u32 ) ;
958
917
}
959
918
if parsed < 0 {
960
919
return AppLayerResult :: err ( ) ;
961
920
}
962
- self . bytes_consumed += parsed ;
963
- input_len -= parsed as usize ;
921
+ } else {
922
+ frag_bytes_consumed = DCERPC_HDR_LEN ;
964
923
}
965
924
966
925
let fraglen = self . get_hdr_fraglen ( ) . unwrap_or ( 0 ) ;
967
926
968
- if ( input_len + self . bytes_consumed as usize ) < fraglen as usize {
927
+ if cur_i . len ( ) < ( fraglen - frag_bytes_consumed ) as usize {
969
928
SCLogDebug ! ( "Possibly fragmented data, waiting for more.." ) ;
970
- return AppLayerResult :: incomplete ( self . bytes_consumed as u32 , ( fraglen - self . bytes_consumed as u16 ) as u32 ) ;
971
- } else {
972
- self . query_completed = true ;
929
+ return AppLayerResult :: incomplete ( parsed as u32 , fraglen as u32 - parsed as u32 ) ;
973
930
}
974
931
975
932
let current_call_id = self . get_hdr_call_id ( ) . unwrap_or ( 0 ) ;
@@ -1033,23 +990,15 @@ impl DCERPCState {
1033
990
}
1034
991
_ => {
1035
992
SCLogDebug ! ( "Unrecognized packet type: {:?}" , x) ;
1036
- self . clean_buffer ( direction) ;
1037
993
return AppLayerResult :: err ( ) ;
1038
994
}
1039
995
} ,
1040
996
None => {
1041
997
return AppLayerResult :: err ( ) ;
1042
998
}
1043
999
}
1044
- self . bytes_consumed += retval;
1045
1000
1046
- // If the query has been completed, clean the buffer and reset the direction
1047
- if self . query_completed {
1048
- self . clean_buffer ( direction) ;
1049
- self . reset_direction ( direction) ;
1050
- }
1051
1001
self . post_gap_housekeeping ( direction) ;
1052
- self . prev_dir = direction;
1053
1002
self . header = None ;
1054
1003
return AppLayerResult :: ok ( ) ;
1055
1004
}
@@ -1892,7 +1841,6 @@ mod tests {
1892
1841
0xFF ,
1893
1842
] ;
1894
1843
let mut dcerpc_state = DCERPCState :: new ( ) ;
1895
- dcerpc_state. data_needed_for_dir = Direction :: ToClient ;
1896
1844
assert_eq ! (
1897
1845
AppLayerResult :: ok( ) ,
1898
1846
dcerpc_state. handle_input_data( bind_ack, Direction :: ToClient )
@@ -2180,7 +2128,6 @@ mod tests {
2180
2128
) ;
2181
2129
if let Some ( ref back) = dcerpc_state. bindack {
2182
2130
assert_eq ! ( 1 , back. accepted_uuid_list. len( ) ) ;
2183
- dcerpc_state. data_needed_for_dir = Direction :: ToServer ;
2184
2131
assert_eq ! ( 11 , back. accepted_uuid_list[ 0 ] . ctxid) ;
2185
2132
assert_eq ! ( expected_uuid3, back. accepted_uuid_list[ 0 ] . uuid) ;
2186
2133
}
0 commit comments