Skip to content

Commit

Permalink
Some TPKT packet could have less than 7 bytes as expected by specific…
Browse files Browse the repository at this point in the history
…ation
  • Loading branch information
citronneur committed Mar 9, 2021
1 parent 600d6e5 commit 7ac880d
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/core/tpkt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ impl<S: Read + Write> Client<S> {

// Minimal size must be 7
// https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-rdpbcgr/18a27ef9-6f9a-4501-b000-94b1fe3c2c10
if size.inner() < 7 {
if size.inner() < 4 {
Err(Error::RdpError(RdpError::new(RdpErrorKind::InvalidSize, "Invalid minimal size for TPKT")))
}
else {
Expand All @@ -155,14 +155,14 @@ impl<S: Read + Write> Client<S> {
hi_length.read(&mut Cursor::new(self.transport.read(1)?))?;
let length: u16 = ((short_length & !0x80) as u16) << 8;
let length = length | hi_length as u16;
if length < 7 {
if length < 3 {
Err(Error::RdpError(RdpError::new(RdpErrorKind::InvalidSize, "Invalid minimal size for TPKT")))
} else {
Ok(Payload::FastPath(sec_flag, Cursor::new(self.transport.read(length as usize - 3)?)))
}
}
else {
if short_length < 7 {
if short_length < 2 {
Err(Error::RdpError(RdpError::new(RdpErrorKind::InvalidSize, "Invalid minimal size for TPKT")))
} else {
Ok(Payload::FastPath(sec_flag, Cursor::new(self.transport.read(short_length as usize - 2)?)))
Expand Down

0 comments on commit 7ac880d

Please sign in to comment.