]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
rust/nfs: don't panic on malformed NFS traffic
authorNick Price <nick@spun.io>
Thu, 28 Dec 2017 16:11:17 +0000 (11:11 -0500)
committerVictor Julien <victor@inliniac.net>
Mon, 8 Jan 2018 08:51:57 +0000 (09:51 +0100)
Instead set events.

rust/src/nfs/nfs.rs

index 60a5107b8538c0d47a1dfaab29602de6950b8116..279bc0739d6f846de8e4cd1b378ade4d1039b78e 100644 (file)
@@ -95,9 +95,8 @@ pub static mut SURICATA_NFS3_FILE_CONFIG: Option<&'static SuricataFileContext> =
 #[repr(u32)]
 pub enum NFSEvent {
     MalformedData = 0,
-    /* remove 'Padding' when more events are added. Rustc 1.7 won't
-     *   accept a single field enum with repr(u32) */
-    Padding,
+    NonExistingVersion = 1,
+    UnsupportedVersion = 2,
 }
 
 #[derive(Debug)]
@@ -1061,15 +1060,24 @@ impl NFSState {
         }
 
         match xidmap.progver {
+            2 => {
+                SCLogDebug!("NFSv2 reply record");
+                return self.process_reply_record_v2(r, &xidmap);
+            },
             3 => {
                 SCLogDebug!("NFSv3 reply record");
                 return self.process_reply_record_v3(r, &mut xidmap);
             },
-            2 => {
-                SCLogDebug!("NFSv2 reply record");
-                return self.process_reply_record_v2(r, &xidmap);
+            4 => {
+                SCLogDebug!("NFSv4 unsupported");
+                self.set_event(NFSEvent::UnsupportedVersion);
+                return 0;
+            },
+            _ => {
+                SCLogDebug!("Invalid NFS version");
+                self.set_event(NFSEvent::NonExistingVersion);
+                return 0;
             },
-            _ => { panic!("unsupported NFS version"); },
         }
     }