frame: reject bad opcodes early

Signed-off-by: Alexey Galakhov <agalakhov@snapview.de>
pull/37/head
Alexey Galakhov 7 years ago
parent 9bd65feaeb
commit fdb1a0ed50
  1. 16
      src/protocol/frame/frame.rs

@ -342,6 +342,14 @@ impl Frame {
None
};
// Disallow bad opcode
match opcode {
OpCode::Control(Control::Reserved(_)) | OpCode::Data(Data::Reserved(_)) => {
return Err(Error::Protocol(format!("Encountered invalid opcode: {}", first & 0x0F).into()))
}
_ => ()
}
// Make sure `length` is not too big (fits into `usize`).
if length > usize::max_value() as u64 {
return Err(Error::Capacity(format!("Message length too big: {}", length).into()));
@ -361,14 +369,6 @@ impl Frame {
}
}
// Disallow bad opcode
match opcode {
OpCode::Control(Control::Reserved(_)) | OpCode::Data(Data::Reserved(_)) => {
return Err(Error::Protocol(format!("Encountered invalid opcode: {}", first & 0x0F).into()))
}
_ => ()
}
let frame = Frame {
finished: finished,
rsv1: rsv1,

Loading…
Cancel
Save