]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
smb: update return type of GAP handling
authorVictor Julien <victor@inliniac.net>
Fri, 13 Mar 2020 09:13:56 +0000 (10:13 +0100)
committerVictor Julien <victor@inliniac.net>
Tue, 17 Mar 2020 21:02:19 +0000 (22:02 +0100)
rust/src/smb/smb.rs
src/app-layer-smb.c

index 4e1a3e7fa5000ed34972715a6f2e348dd607cb77..c8fc4fcdee5fa0b1b11c850eafdd315784b1a851 100644 (file)
@@ -1752,7 +1752,7 @@ impl SMBState {
 
     /// handle a gap in the TOSERVER direction
     /// returns: 0 ok, 1 unrecoverable error
-    pub fn parse_tcp_data_ts_gap(&mut self, gap_size: u32) -> u32 {
+    pub fn parse_tcp_data_ts_gap(&mut self, gap_size: u32) -> AppLayerResult {
         let consumed = self.handle_skip(STREAM_TOSERVER, gap_size);
         if consumed < gap_size {
             let new_gap_size = gap_size - consumed;
@@ -1762,18 +1762,18 @@ impl SMBState {
             if consumed2 > new_gap_size {
                 SCLogDebug!("consumed more than GAP size: {} > {}", consumed2, new_gap_size);
                 self.set_event(SMBEvent::InternalError);
-                return 1;
+                return AppLayerResult::err();
             }
         }
         SCLogDebug!("GAP of size {} in toserver direction", gap_size);
         self.ts_ssn_gap = true;
         self.ts_gap = true;
-        return 0
+        return AppLayerResult::ok();
     }
 
     /// handle a gap in the TOCLIENT direction
     /// returns: 0 ok, 1 unrecoverable error
-    pub fn parse_tcp_data_tc_gap(&mut self, gap_size: u32) -> u32 {
+    pub fn parse_tcp_data_tc_gap(&mut self, gap_size: u32) -> AppLayerResult {
         let consumed = self.handle_skip(STREAM_TOCLIENT, gap_size);
         if consumed < gap_size {
             let new_gap_size = gap_size - consumed;
@@ -1783,13 +1783,13 @@ impl SMBState {
             if consumed2 > new_gap_size {
                 SCLogDebug!("consumed more than GAP size: {} > {}", consumed2, new_gap_size);
                 self.set_event(SMBEvent::InternalError);
-                return 1;
+                return AppLayerResult::err();
             }
         }
         SCLogDebug!("GAP of size {} in toclient direction", gap_size);
         self.tc_ssn_gap = true;
         self.tc_gap = true;
-        return 0
+        return AppLayerResult::ok();
     }
 
     pub fn trunc_ts(&mut self) {
@@ -1862,12 +1862,9 @@ pub extern "C" fn rs_smb_parse_request_tcp(flow: &mut Flow,
 pub extern "C" fn rs_smb_parse_request_tcp_gap(
                                         state: &mut SMBState,
                                         input_len: u32)
-                                        -> i8
+                                        -> AppLayerResult
 {
-    if state.parse_tcp_data_ts_gap(input_len as u32) == 0 {
-        return 0;
-    }
-    return -1;
+    state.parse_tcp_data_ts_gap(input_len as u32)
 }
 
 
@@ -1897,12 +1894,9 @@ pub extern "C" fn rs_smb_parse_response_tcp(flow: &mut Flow,
 pub extern "C" fn rs_smb_parse_response_tcp_gap(
                                         state: &mut SMBState,
                                         input_len: u32)
-                                        -> i8
+                                        -> AppLayerResult
 {
-    if state.parse_tcp_data_tc_gap(input_len as u32) == 0 {
-        return 0;
-    }
-    return -1;
+    state.parse_tcp_data_tc_gap(input_len as u32)
 }
 
 // probing parser
index d3b2d3416aab309425b7babb393f6d390ff28933..7b7c68c7a04cdee67c8b8407e827a2f136676381 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (C) 2017 Open Information Security Foundation
+/* Copyright (C) 2017-2020 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
@@ -39,12 +39,9 @@ static AppLayerResult SMBTCPParseRequest(Flow *f, void *state,
     rs_smb_setfileflags(0, state, file_flags|FILE_USE_DETECT);
 
     if (input == NULL && input_len > 0) {
-        int res = rs_smb_parse_request_tcp_gap(state, input_len);
-        SCLogDebug("SMB request GAP of %u bytes, retval %d", input_len, res);
-        if (res != 0) {
-            SCReturnStruct(APP_LAYER_ERROR);
-        }
-        SCReturnStruct(APP_LAYER_OK);
+        AppLayerResult res = rs_smb_parse_request_tcp_gap(state, input_len);
+        SCLogDebug("SMB request GAP of %u bytes, retval %d", input_len, res.status);
+        SCReturnStruct(res);
     } else {
         AppLayerResult res = rs_smb_parse_request_tcp(f, state, pstate,
                 input, input_len, local_data, flags);
@@ -64,13 +61,9 @@ static AppLayerResult SMBTCPParseResponse(Flow *f, void *state,
 
     SCLogDebug("SMBTCPParseResponse %p/%u", input, input_len);
     if (input == NULL && input_len > 0) {
-        int res = rs_smb_parse_response_tcp_gap(state, input_len);
-        if (res != 0) {
-            SCLogDebug("SMB response%s of %u bytes, retval %d",
-                    (input == NULL && input_len > 0) ? " is GAP" : "", input_len, res);
-            SCReturnStruct(APP_LAYER_ERROR);
-        }
-        SCReturnStruct(APP_LAYER_OK);
+        AppLayerResult res = rs_smb_parse_response_tcp_gap(state, input_len);
+        SCLogDebug("SMB response GAP of %u bytes, retval %d", input_len, res.status);
+        SCReturnStruct(res);
     } else {
         AppLayerResult res = rs_smb_parse_response_tcp(f, state, pstate,
                 input, input_len, local_data, flags);