aboutsummaryrefslogtreecommitdiff
path: root/src/protocol/commands/_m.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/protocol/commands/_m.rs')
-rw-r--r--src/protocol/commands/_m.rs14
1 files changed, 8 insertions, 6 deletions
diff --git a/src/protocol/commands/_m.rs b/src/protocol/commands/_m.rs
index f7570ad..9271310 100644
--- a/src/protocol/commands/_m.rs
+++ b/src/protocol/commands/_m.rs
@@ -9,6 +9,7 @@ pub struct m<'a> {
}
impl<'a> ParseCommand<'a> for m<'a> {
+ #[inline(always)]
fn from_packet(buf: PacketBuf<'a>) -> Option<Self> {
// the total packet buffer currently looks like:
//
@@ -29,20 +30,21 @@ impl<'a> ParseCommand<'a> for m<'a> {
// +------+------------------+------------------------------------------------+
let (buf, body_range) = buf.into_raw_buf();
- let body = &mut buf[body_range.start..];
+ let body = buf.get_mut(body_range.start..body_range.end)?;
- // should return 3 slices: the addr (hex-encoded), len (hex-encoded), and the
- // "rest" of the buffer
- let mut body = body.split_mut(|b| *b == b',' || *b == b'#');
+ let mut body = body.split_mut(|b| *b == b',');
let addr = decode_hex_buf(body.next()?).ok()?;
let addr_len = addr.len();
let len = decode_hex(body.next()?).ok()?;
- drop(body);
+ // ensures that `split_at_mut` doesn't panic
+ if buf.len() < body_range.start + addr_len {
+ return None;
+ }
let (addr, buf) = buf.split_at_mut(body_range.start + addr_len);
- let addr = &addr[b"$m".len()..];
+ let addr = addr.get(b"$m".len()..)?;
Some(m { addr, len, buf })
}