aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoriximeow <me@iximeow.net>2020-08-02 21:04:59 -0700
committeriximeow <me@iximeow.net>2020-08-09 01:38:57 -0700
commitaa3df6a360551c2a770863c4324101db7b22f79f (patch)
tree016ff09f50a35f877151b16a1d27aa6dcffb4b4f
parent4112c2282a207ab0738db44dfc69caf68fe50de9 (diff)
handle bad fe/ff opcode cases better
-rw-r--r--src/long_mode/mod.rs19
1 files changed, 10 insertions, 9 deletions
diff --git a/src/long_mode/mod.rs b/src/long_mode/mod.rs
index b620092..ef7f8c9 100644
--- a/src/long_mode/mod.rs
+++ b/src/long_mode/mod.rs
@@ -5966,20 +5966,22 @@ fn read_operands<T: Iterator<Item=u8>>(decoder: &InstDecoder, mut bytes_iter: T,
},
OperandCode::ModRM_0xfe_Eb => {
instruction.operands[0] = mem_oper;
+ let r = (modrm >> 3) & 7;
+ if r >= 2 {
+ return Err(DecodeError::InvalidOpcode);
+ }
instruction.opcode = [
Opcode::INC,
Opcode::DEC,
- Opcode::Invalid,
- Opcode::Invalid,
- Opcode::Invalid,
- Opcode::Invalid,
- Opcode::Invalid,
- Opcode::Invalid
- ][((modrm >> 3) & 7) as usize];
+ ][r as usize];
instruction.operand_count = 1;
}
OperandCode::ModRM_0xff_Ev => {
instruction.operands[0] = mem_oper;
+ let r = (modrm >> 3) & 7;
+ if r == 7 {
+ return Err(DecodeError::InvalidOpcode);
+ }
let opcode = [
Opcode::INC,
Opcode::DEC,
@@ -5988,8 +5990,7 @@ fn read_operands<T: Iterator<Item=u8>>(decoder: &InstDecoder, mut bytes_iter: T,
Opcode::JMP,
Opcode::JMPF,
Opcode::PUSH,
- Opcode::Invalid
- ][((modrm >> 3) & 7) as usize];
+ ][r as usize];
if instruction.operands[0] == OperandSpec::RegMMM {
if opcode == Opcode::CALL || opcode == Opcode::JMP {
instruction.modrm_mmm.bank = RegisterBank::Q;