diff options
author | Nemanja Ivanovic <nemanja.i.ibm@gmail.com> | 2023-02-02 12:38:08 -0600 |
---|---|---|
committer | Nemanja Ivanovic <nemanja.i.ibm@gmail.com> | 2023-02-02 12:39:49 -0600 |
commit | c86f8d4276aee8956711829e49c9969cd0223590 (patch) | |
tree | 88c21f5ee859530d5a6ee1686f87a991dda21a6c /llvm/lib/Target/PowerPC/Disassembler/PPCDisassembler.cpp | |
parent | 089bfedfb828c2675f3cc57d6ecac1a87ca243a1 (diff) | |
download | llvm-c86f8d4276aee8956711829e49c9969cd0223590.zip llvm-c86f8d4276aee8956711829e49c9969cd0223590.tar.gz llvm-c86f8d4276aee8956711829e49c9969cd0223590.tar.bz2 |
[PowerPC] Don't crash when disassembling invalid immediate
There is an assert in the disassembler functions to ensure
that the immediate is the appropriate width. However,
sometimes what is being disassembled is not instructions
but data that happens to have the bit pattern of an existing
instruction but invalid operands. It is valid for such
things to exist in the text section so we don't want
to crash when disassembling such a thing.
This patch removes the asserts and produces a disassembler
failure for such cases.
Diffstat (limited to 'llvm/lib/Target/PowerPC/Disassembler/PPCDisassembler.cpp')
-rw-r--r-- | llvm/lib/Target/PowerPC/Disassembler/PPCDisassembler.cpp | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/llvm/lib/Target/PowerPC/Disassembler/PPCDisassembler.cpp b/llvm/lib/Target/PowerPC/Disassembler/PPCDisassembler.cpp index 1629f1b..5704727 100644 --- a/llvm/lib/Target/PowerPC/Disassembler/PPCDisassembler.cpp +++ b/llvm/lib/Target/PowerPC/Disassembler/PPCDisassembler.cpp @@ -239,7 +239,8 @@ template <unsigned N> static DecodeStatus decodeUImmOperand(MCInst &Inst, uint64_t Imm, int64_t Address, const MCDisassembler *Decoder) { - assert(isUInt<N>(Imm) && "Invalid immediate"); + if (!isUInt<N>(Imm)) + return MCDisassembler::Fail; Inst.addOperand(MCOperand::createImm(Imm)); return MCDisassembler::Success; } @@ -248,7 +249,8 @@ template <unsigned N> static DecodeStatus decodeSImmOperand(MCInst &Inst, uint64_t Imm, int64_t Address, const MCDisassembler *Decoder) { - assert(isUInt<N>(Imm) && "Invalid immediate"); + if (!isUInt<N>(Imm)) + return MCDisassembler::Fail; Inst.addOperand(MCOperand::createImm(SignExtend64<N>(Imm))); return MCDisassembler::Success; } |