Skip to content

Commit 25706ea

Browse files
krussmarcmo
authored andcommitted
Fix inconsistent payload-length check
1 parent 32b0358 commit 25706ea

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

src/dlt.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1874,10 +1874,10 @@ impl From<&MessageType> for u8 {
18741874
{
18751875
u8::from(x)
18761876
}
1877-
MessageType::ApplicationTrace(x) => 0x1 << 1 | u8::from(x),
1878-
MessageType::NetworkTrace(x) => 0x2 << 1 | u8::from(x),
1879-
MessageType::Control(x) => 0x3 << 1 | u8::from(x),
1880-
MessageType::Unknown((mstp, mtin)) => mstp << 1 | mtin << 4,
1877+
MessageType::ApplicationTrace(x) => (0x1 << 1) | u8::from(x),
1878+
MessageType::NetworkTrace(x) => (0x2 << 1) | u8::from(x),
1879+
MessageType::Control(x) => (0x3 << 1) | u8::from(x),
1880+
MessageType::Unknown((mstp, mtin)) => (mstp << 1) | (mtin << 4),
18811881
}
18821882
}
18831883
}

src/parse.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ pub(crate) fn dlt_standard_header(input: &[u8]) -> IResult<&[u8], StandardHeader
252252
Ok((
253253
input,
254254
StandardHeader::new(
255-
header_type_byte >> 5 & 0b111,
255+
(header_type_byte >> 5) & 0b111,
256256
if (header_type_byte & BIG_ENDIAN_FLAG) != 0 {
257257
Endianness::Big
258258
} else {
@@ -729,10 +729,10 @@ fn dlt_payload<T: NomByteOrder>(
729729
Err(e) => Err(e),
730730
}
731731
} else {
732-
if input.len() < 4 {
732+
if payload_length < 4 {
733733
return Err(nom::Err::Failure(DltParseError::ParsingHickup(format!(
734734
"error, payload too short {}",
735-
input.len()
735+
payload_length
736736
))));
737737
}
738738
match tuple((T::parse_u32, take(payload_length - 4)))(input) {
@@ -1002,6 +1002,7 @@ pub(crate) fn skip_till_after_next_storage_header(
10021002
}
10031003
}
10041004

1005+
#[allow(clippy::useless_conversion)]
10051006
/// Remove the storage header from the input if present
10061007
pub fn skip_storage_header(input: &[u8]) -> Result<(&[u8], u64), DltParseError> {
10071008
let (i, (_, _, _)): (&[u8], _) = tuple((tag("DLT"), tag(&[0x01]), take(12usize)))(input)
@@ -1015,6 +1016,7 @@ pub fn skip_storage_header(input: &[u8]) -> Result<(&[u8], u64), DltParseError>
10151016
}
10161017
}
10171018

1019+
#[allow(clippy::useless_conversion)]
10181020
/// Skip one dlt message in the input stream in an efficient way
10191021
/// pre: message to be parsed contains a storage header
10201022
pub fn dlt_consume_msg(input: &[u8]) -> Result<(&[u8], Option<u64>), DltParseError> {

0 commit comments

Comments
 (0)