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

Daniel Sanders via llvm-commits llvm-commits at lists.llvm.org
Fri Sep 18 07:20:55 PDT 2015


Author: dsanders
Date: Fri Sep 18 09:20:54 2015
New Revision: 247990

URL: http://llvm.org/viewvc/llvm-project?rev=247990&view=rev
Log:
[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

Added:
    llvm/trunk/test/MC/Disassembler/Mips/micromips32r3/
    llvm/trunk/test/MC/Disassembler/Mips/micromips32r3/invalid.txt
Modified:
    llvm/trunk/lib/Target/Mips/Disassembler/MipsDisassembler.cpp

Modified: llvm/trunk/lib/Target/Mips/Disassembler/MipsDisassembler.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/Mips/Disassembler/MipsDisassembler.cpp?rev=247990&r1=247989&r2=247990&view=diff
==============================================================================
--- llvm/trunk/lib/Target/Mips/Disassembler/MipsDisassembler.cpp (original)
+++ llvm/trunk/lib/Target/Mips/Disassembler/MipsDisassembler.cpp Fri Sep 18 09:20:54 2015
@@ -1919,11 +1919,17 @@ static DecodeStatus DecodeRegListOperand
   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]));
 

Added: llvm/trunk/test/MC/Disassembler/Mips/micromips32r3/invalid.txt
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/Disassembler/Mips/micromips32r3/invalid.txt?rev=247990&view=auto
==============================================================================
--- llvm/trunk/test/MC/Disassembler/Mips/micromips32r3/invalid.txt (added)
+++ llvm/trunk/test/MC/Disassembler/Mips/micromips32r3/invalid.txt Fri Sep 18 09:20:54 2015
@@ -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




More information about the llvm-commits mailing list