From: Christoph Egger Date: Wed, 25 Mar 2015 12:40:51 +0000 (+0100) Subject: Proper error handling when opening binary X-Git-Tag: v0.1~18 X-Git-Url: https://git.siccegge.de//index.cgi?a=commitdiff_plain;h=143c915f348d3db791b6b27f7e21a2a4762e6039;p=frida%2Ffrida.git Proper error handling when opening binary Fail properly when the supplied file is not a recognized binary Closes T25 --- diff --git a/src/disassembler/llvm/LLVMDisassembler.cxx b/src/disassembler/llvm/LLVMDisassembler.cxx index b97f93f..8ffb417 100644 --- a/src/disassembler/llvm/LLVMDisassembler.cxx +++ b/src/disassembler/llvm/LLVMDisassembler.cxx @@ -27,12 +27,22 @@ namespace { * */ Disassembler * createLLVMDisassembler(const std::string& filename, InformationManager* manager) { + log4cxx::LoggerPtr logger(log4cxx::Logger::getLogger("disassembler.LLVMDisassembler")); if (filename == "") return NULL; - std::unique_ptr o; - o.reset(createBinary(filename).get()); - Binary * op = o.release(); + auto retval = createBinary(filename); + if (error_code ec = retval.getError()) { + LOG4CXX_ERROR(logger, ec.message()); + return NULL; + } + + Binary * op = retval.get(); + + if (!op) { + LOG4CXX_ERROR(logger, "Could not open " << filename); + return NULL; + } // ELFType if (ELF32LEObjectFile * object = dyn_cast(op)) {