From ba774a258c92c8c466e23535cf1b167b8c3c80c6 Mon Sep 17 00:00:00 2001 From: Florian Lukas Date: Thu, 3 Apr 2014 14:56:41 +0200 Subject: [PATCH] util/llvmdisassembler: fix section end symbols Somehow, while iterating symbols in a section, it can happen that the last symbol start address is equal to the section size, which means it is beyond the section end. In this case the LLVM getInstruction() method does not return a failure, but a zero-size instruction, resulting in an infinite loop. Now, if beyond section limits, the iteration is aborted. Additionally, an assertion checks for disassembled zero-size instructions. Change-Id: Id8a355475161150d3ee919cd6cf603d4ff26b228 --- src/core/util/llvmdisassembler/LLVMDisassembler.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/core/util/llvmdisassembler/LLVMDisassembler.cpp b/src/core/util/llvmdisassembler/LLVMDisassembler.cpp index 6e2977aa..c5d03da7 100644 --- a/src/core/util/llvmdisassembler/LLVMDisassembler.cpp +++ b/src/core/util/llvmdisassembler/LLVMDisassembler.cpp @@ -85,7 +85,10 @@ void LLVMDisassembler::disassemble() uint64_t End; // The end is either the size of the section or the beginning of the next // symbol. - if (si == se - 1) + if (Start >= SectSize) + // we are beyond the end of the section + break; + else if (si == se - 1) End = SectSize; // Make sure this symbol takes up space. else if (Symbols[si + 1].first != Start) @@ -98,7 +101,7 @@ void LLVMDisassembler::disassemble() MCInst Inst; if (disas->getInstruction(Inst, Size, memoryObject, Index, - nulls(), nulls())) { + nulls(), nulls()) == MCDisassembler::Success) { const MCInstrDesc &desc = this->instr_info->get(Inst.getOpcode()); // Inst.dump(); Instr instr_info; @@ -107,6 +110,8 @@ void LLVMDisassembler::disassemble() instr_info.address = SectionAddr + Index; instr_info.conditional_branch = desc.isConditionalBranch(); + assert( Size > 0 && "zero size instruction disassembled" ); + unsigned int pos = 0; for (MCInst::iterator it = Inst.begin(); it != Inst.end(); ++it) {