From eea548b1889aae3a2bfa6b29c6a6cd3c09c39aac Mon Sep 17 00:00:00 2001 From: Daniel Prilik Date: Sun, 6 Sep 2020 16:04:10 -0400 Subject: [PATCH] fix parse error when using fixed-size packet buf hmm, not sure when this bug was introduced... Well, it's fixed now, so that's good. --- src/gdbstub_impl/mod.rs | 5 +---- src/protocol/packet.rs | 2 +- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/src/gdbstub_impl/mod.rs b/src/gdbstub_impl/mod.rs index 4a0ca652..c8cf27a2 100644 --- a/src/gdbstub_impl/mod.rs +++ b/src/gdbstub_impl/mod.rs @@ -192,10 +192,7 @@ impl GdbStubImpl { buf.push(conn.read().map_err(Error::ConnectionRead)?)?; } - drop(buf); - - let len = pkt_buf.len(); - match Packet::from_buf(target, &mut pkt_buf.as_mut()[..len]) { + match Packet::from_buf(target, pkt_buf.as_mut()) { Ok(packet) => Ok(packet), Err(e) => { // TODO: preserve this context within Error::PacketParse diff --git a/src/protocol/packet.rs b/src/protocol/packet.rs index 1b5f21de..2b6cfb95 100644 --- a/src/protocol/packet.rs +++ b/src/protocol/packet.rs @@ -44,7 +44,7 @@ impl<'a> PacketBuf<'a> { // split buffer into body and checksum components let (body, checksum) = pkt_buf.split_at_mut(end_of_body); let body = &mut body[1..]; // skip the '$' - let checksum = &mut checksum[1..]; // skip the '#' + let checksum = &mut checksum[1..][..2]; // skip the '#' // validate the checksum let checksum = decode_hex(checksum).map_err(|_| PacketParseError::MalformedChecksum)?;