summaryrefslogtreecommitdiffstats
path: root/llvm/unittests/MC/Disassembler.cpp
diff options
context:
space:
mode:
authorFangrui Song <maskray@google.com>2020-01-13 10:34:10 -0800
committerFangrui Song <maskray@google.com>2020-01-13 10:42:21 -0800
commit64a93afc3c630c39e5c583e4f67aef5821d635b6 (patch)
treec5a68796c0cabeea934fddd88306e4c9d19a8234 /llvm/unittests/MC/Disassembler.cpp
parent484a7472f1aa6906f2b66dc33bcf69cc8d5b9f29 (diff)
downloadbcm5719-llvm-64a93afc3c630c39e5c583e4f67aef5821d635b6.tar.gz
bcm5719-llvm-64a93afc3c630c39e5c583e4f67aef5821d635b6.zip
[X86][Disassembler] Fix a bug when disassembling an empty string
readPrefixes() assumes insn->bytes is non-empty. The code path is not exercised in llvm-mc because llvm-mc does not feed empty input to MCDisassembler::getInstruction(). This bug is uncovered by a5994c789a2982a770254ae1607b5b4cb641f73c. An empty string did not crash before because the deleted regionReader() allowed UINT64_C(-1) as insn->readerCursor. Bytes.size() <= Address -> R->Base 0 <= UINT64_C(-1) - UINT32_C(-1)
Diffstat (limited to 'llvm/unittests/MC/Disassembler.cpp')
-rw-r--r--llvm/unittests/MC/Disassembler.cpp4
1 files changed, 4 insertions, 0 deletions
diff --git a/llvm/unittests/MC/Disassembler.cpp b/llvm/unittests/MC/Disassembler.cpp
index cdb344474ca..3f9e6e5501e 100644
--- a/llvm/unittests/MC/Disassembler.cpp
+++ b/llvm/unittests/MC/Disassembler.cpp
@@ -38,6 +38,10 @@ TEST(Disassembler, X86Test) {
unsigned NumBytes = sizeof(Bytes);
unsigned PC = 0;
+ InstSize =
+ LLVMDisasmInstruction(DCR, BytesP, 0, PC, OutString, OutStringSize);
+ EXPECT_EQ(InstSize, 0U);
+
InstSize = LLVMDisasmInstruction(DCR, BytesP, NumBytes, PC, OutString,
OutStringSize);
EXPECT_EQ(InstSize, 1U);
OpenPOWER on IntegriCloud