[mips][microMIPS] Fix an invalid read for lwm32 and reserved reglist values.

Summary:
Some values of 'reglist' are reserved and cause the disassembler to read past
the end of the Regs array. Treat lwm32's containing reserved values as invalid
instructions.

Reviewers: zoran.jovanovic

Subscribers: llvm-commits

Differential Revision: http://reviews.llvm.org/D12959

llvm-svn: 247990
This commit is contained in:
Daniel Sanders 2015-09-18 14:20:54 +00:00
parent d90e2ebdf6
commit df19a5e605
2 changed files with 10 additions and 0 deletions

View File

@ -1919,11 +1919,17 @@ static DecodeStatus DecodeRegListOperand(MCInst &Inst,
unsigned RegNum;
unsigned RegLst = fieldFromInstruction(Insn, 21, 5);
// Empty register lists are not allowed.
if (RegLst == 0)
return MCDisassembler::Fail;
RegNum = RegLst & 0xf;
// RegLst values 10-15, and 26-31 are reserved.
if (RegNum > 9)
return MCDisassembler::Fail;
for (unsigned i = 0; i < RegNum; i++)
Inst.addOperand(MCOperand::createReg(Regs[i]));

View File

@ -0,0 +1,4 @@
# RUN: llvm-mc --disassemble %s -triple=mips-unknown-linux -mattr=micromips \
# RUN: 2>&1 | FileCheck %s
0x21 0xe2 0x5c 0x71 # CHECK: :[[@LINE]]:1: warning: invalid instruction encoding