]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
smb: prevents integer underflow
authorPhilippe Antoine <contact@catenacyber.fr>
Fri, 8 Apr 2022 09:23:09 +0000 (11:23 +0200)
committerVictor Julien <vjulien@oisf.net>
Mon, 11 Apr 2022 17:11:01 +0000 (19:11 +0200)
Ticket: 5246

If msg_id is 0, we cannot find the previous request

rust/src/smb/smb2.rs

index e85906d8d3f95b38b958150a8e5759dac255d6a5..b77e359c362d031219918b5b676031b2f638f120 100644 (file)
@@ -376,10 +376,14 @@ pub fn smb2_request_record<'b>(state: &mut SMBState, r: &Smb2Record<'b>)
                                 None => {
                                     // try to find latest created file in case of chained commands
                                     let mut guid_key = SMBCommonHdr::from2(r, SMBHDR_TYPE_FILENAME);
-                                    guid_key.msg_id = guid_key.msg_id - 1;
-                                    match state.ssn2vec_map.get(&guid_key) {
-                                        Some(n) => { n.to_vec() },
-                                        None => { b"<unknown>".to_vec()},
+                                    if guid_key.msg_id == 0 {
+                                        b"<unknown>".to_vec()
+                                    } else {
+                                        guid_key.msg_id = guid_key.msg_id - 1;
+                                        match state.ssn2vec_map.get(&guid_key) {
+                                            Some(n) => { n.to_vec() },
+                                            None => { b"<unknown>".to_vec()},
+                                        }
                                     }
                                 },
                             };