From: Jason Ish Date: Mon, 13 Aug 2018 04:44:02 +0000 (-0600) Subject: dhcp: check length of option before accessing X-Git-Tag: suricata-4.1.0-rc2~115 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1c6bc5754c4a808d1fc980081b1bda3a857db1ee;p=thirdparty%2Fsuricata.git dhcp: check length of option before accessing Prevent Rust index out of bounds panic. Redmine issue: https://redmine.openinfosecfoundation.org/issues/2571 --- diff --git a/rust/src/dhcp/logger.rs b/rust/src/dhcp/logger.rs index 8e3a5f7ba5..4951f9a6db 100644 --- a/rust/src/dhcp/logger.rs +++ b/rust/src/dhcp/logger.rs @@ -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) {