[PATCH] D12959: [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 06:39:48 PDT 2015
dsanders created this revision.
dsanders added a reviewer: zoran.jovanovic.
dsanders added a subscriber: llvm-commits.
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.
http://reviews.llvm.org/D12959
Files:
lib/Target/Mips/Disassembler/MipsDisassembler.cpp
test/MC/Disassembler/Mips/micromips32r3/
test/MC/Disassembler/Mips/micromips32r3/invalid.txt
Index: test/MC/Disassembler/Mips/micromips32r3/invalid.txt
===================================================================
--- /dev/null
+++ test/MC/Disassembler/Mips/micromips32r3/invalid.txt
@@ -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
Index: lib/Target/Mips/Disassembler/MipsDisassembler.cpp
===================================================================
--- lib/Target/Mips/Disassembler/MipsDisassembler.cpp
+++ lib/Target/Mips/Disassembler/MipsDisassembler.cpp
@@ -1919,11 +1919,17 @@
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]));
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D12959.35078.patch
Type: text/x-patch
Size: 1075 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150918/a187aea3/attachment.bin>
More information about the llvm-commits
mailing list