diff --git a/Cargo.toml b/Cargo.toml index ec977e9..bfaa860 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "someip_parse" -version = "0.6.1" +version = "0.6.2" edition = "2021" rust-version = "1.60" authors = ["Julian Schmid "] diff --git a/examples/count_messages_by_id.rs b/examples/count_messages_by_id.rs index 238f2b4..ddcbc1c 100644 --- a/examples/count_messages_by_id.rs +++ b/examples/count_messages_by_id.rs @@ -104,7 +104,7 @@ struct Stats { } #[derive(Debug)] -enum Error { +pub enum Error { IoError(std::io::Error), PcapError(rpcap::PcapError), } diff --git a/examples/print_messages.rs b/examples/print_messages.rs index 9de51cc..7bd5ae1 100644 --- a/examples/print_messages.rs +++ b/examples/print_messages.rs @@ -54,7 +54,7 @@ fn main() -> Result<(), Error> { } #[derive(Debug)] -enum Error { +pub enum Error { IoError(std::io::Error), PcapError(rpcap::PcapError), } diff --git a/proptest-regressions/someip_header.txt b/proptest-regressions/someip_header.txt index d879574..4c8ab64 100644 --- a/proptest-regressions/someip_header.txt +++ b/proptest-regressions/someip_header.txt @@ -1 +1,2 @@ cc ba538a3dd744b011673fdb42ef76a3b4f53f5c21fc1f42d044f9ca7d53ec720b +cc 04f8332adeb3f83b7ad83f10f8e0da57af3ff865568e2bd7a61ed38b28616e2 diff --git a/src/lib.rs b/src/lib.rs index 02b24c6..1852b70 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -126,7 +126,7 @@ pub const SOMEIP_LEN_OFFSET_TO_PAYLOAD: u32 = 4 * 2; // 2x 32bits ///Maximum payload length supported by some ip. This is NOT the maximum length that is supported when ///sending packets over UDP. This constant is based on the limitation of the length field data type (uint32). -pub const SOMEIP_MAX_PAYLOAD_LEN: u32 = std::u32::MAX - SOMEIP_LEN_OFFSET_TO_PAYLOAD; +pub const SOMEIP_MAX_PAYLOAD_LEN: u32 = u32::MAX - SOMEIP_LEN_OFFSET_TO_PAYLOAD; /// The maximum payload size of an SOMEIP UDP message. /// diff --git a/src/sd.rs b/src/sd.rs index 1197662..fd3c986 100644 --- a/src/sd.rs +++ b/src/sd.rs @@ -331,7 +331,10 @@ impl SdHeader { #[inline] #[cfg(any(target_pointer_width = "32", target_pointer_width = "64"))] - pub fn read_with_flag(reader: &mut T, discard_unknown_option: bool) -> Result { + pub fn read_with_flag( + reader: &mut T, + discard_unknown_option: bool, + ) -> Result { const HEADER_LENGTH: usize = 1 + 3 + 4; // flags + rev + entries length let mut header_bytes: [u8; HEADER_LENGTH] = [0; HEADER_LENGTH]; reader.read_exact(&mut header_bytes)?; @@ -958,7 +961,10 @@ impl SdOption { /// Read the value from a [`std::io::Read`] source. #[inline] - pub fn read_with_flag(reader: &mut T, discard_unknown_option: bool) -> Result<(u16, Self), SdReadError> { + pub fn read_with_flag( + reader: &mut T, + discard_unknown_option: bool, + ) -> Result<(u16, Self), SdReadError> { use self::sd_options::*; use self::SdOption::*; use SdReadError::*; @@ -1602,6 +1608,21 @@ mod tests_sd_option { let result = SdOption::read(&mut cursor); assert_matches!(result, Err(SdReadError::UnknownSdOptionType(0xFF))); } + // unknown option type (non discardable, discard option set) + { + let buffer = [0x00, 0x01, 0xff, 0x00]; + let mut cursor = std::io::Cursor::new(buffer); + let (len, header) = SdOption::read_with_flag(&mut cursor, true).unwrap(); + assert_eq!( + header, + UnknownDiscardableOption { + length: 1, + option_type: 0xff, + } + .into() + ); + assert_eq!(4, len); + } // unknown option type (discardable) { let buffer = [0x00, 0x01, 0xff, 0b1000_0000]; diff --git a/src/someip_header.rs b/src/someip_header.rs index 2c2bd10..82215a6 100644 --- a/src/someip_header.rs +++ b/src/someip_header.rs @@ -567,7 +567,7 @@ mod tests { header.set_method_or_event_id(id); assert_eq!(id, header.event_or_method_id()); - assert_eq!(id > 0x8000, header.is_event()); + assert_eq!(id >= 0x8000, header.is_event()); //serialize and check the slice methods let mut buffer = Vec::new(); @@ -575,7 +575,7 @@ mod tests { buffer.write(&packet.1[..]).unwrap(); let slice = SomeipMsgSlice::from_slice(&buffer[..]).unwrap(); - assert_eq!(id > 0x8000, slice.is_event()); + assert_eq!(id >= 0x8000, slice.is_event()); assert_eq!(id, slice.event_or_method_id()); } }