Skip to content

Commit

Permalink
Fix incorrect range check in multi_tag_message()
Browse files Browse the repository at this point in the history
9656fda introduced a buggy range check when ensuring that the
value's end offset does not extend past the end of the payload.
  • Loading branch information
int08h committed Mar 25, 2018
1 parent 1b74b6f commit ed267f7
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ impl RtMessage {
let start_idx = header_end + value_start;
let end_idx = header_end + value_end;

if end_idx > msg_end || start_idx > end_idx {
if end_idx > bytes_len || start_idx > end_idx {
return Err(Error::InvalidValueLength(tag, end_idx as u32));
}

Expand Down Expand Up @@ -342,6 +342,9 @@ mod test {

// Entire message was read
assert_eq!(encoded.position(), 72);

// Round-trip single-tag message
RtMessage::from_bytes(&msg.encode().unwrap()).unwrap();
}

#[test]
Expand Down Expand Up @@ -392,6 +395,9 @@ mod test {

// Everything was read
assert_eq!(encoded.position() as usize, msg.encoded_size());

// Round-trip multi-tag message
RtMessage::from_bytes(&msg.encode().unwrap()).unwrap();
}

#[test]
Expand Down

0 comments on commit ed267f7

Please sign in to comment.