]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
dhcp: check length of option before accessing
authorJason Ish <ish@unx.ca>
Mon, 13 Aug 2018 04:44:02 +0000 (22:44 -0600)
committerVictor Julien <victor@inliniac.net>
Mon, 20 Aug 2018 09:03:00 +0000 (11:03 +0200)
Prevent Rust index out of bounds panic.

Redmine issue:
https://redmine.openinfosecfoundation.org/issues/2571

rust/src/dhcp/logger.rs

index 8e3a5f7ba5a012c47e3215a790e5611280fff95a..4951f9a6db2286a8c427dd280a81f909abc23838 100644 (file)
@@ -190,18 +190,20 @@ impl DHCPLogger {
     }
 
     fn log_opt_type(&self, js: &Json, option: &DHCPOptGeneric) {
-        let dhcp_type = match option.data[0] {
-            DHCP_TYPE_DISCOVER => "discover",
-            DHCP_TYPE_OFFER => "offer",
-            DHCP_TYPE_REQUEST => "request",
-            DHCP_TYPE_DECLINE => "decline",
-            DHCP_TYPE_ACK => "ack",
-            DHCP_TYPE_NAK => "nak",
-            DHCP_TYPE_RELEASE => "release",
-            DHCP_TYPE_INFORM => "inform",
-            _ => "unknown"
-        };
-        js.set_string("dhcp_type", dhcp_type);
+        if option.data.len() > 0 {
+            let dhcp_type = match option.data[0] {
+                DHCP_TYPE_DISCOVER => "discover",
+                DHCP_TYPE_OFFER => "offer",
+                DHCP_TYPE_REQUEST => "request",
+                DHCP_TYPE_DECLINE => "decline",
+                DHCP_TYPE_ACK => "ack",
+                DHCP_TYPE_NAK => "nak",
+                DHCP_TYPE_RELEASE => "release",
+                DHCP_TYPE_INFORM => "inform",
+                _ => "unknown"
+            };
+            js.set_string("dhcp_type", dhcp_type);
+        }
     }
 
     fn log_opt_parameters(&self, js: &Json, option: &DHCPOptGeneric) {