]> git.siccegge.de Git - frida/frida.git/commitdiff
Proper error handling when opening binary
authorChristoph Egger <Christoph.Egger@fau.de>
Wed, 25 Mar 2015 12:40:51 +0000 (13:40 +0100)
committerChristoph Egger <Christoph.Egger@fau.de>
Wed, 25 Mar 2015 12:40:51 +0000 (13:40 +0100)
Fail properly when the supplied file is not a recognized binary

Closes T25

src/disassembler/llvm/LLVMDisassembler.cxx

index b97f93f7df0618d5bf2ca460d6e071726f5ecfe9..8ffb417cf1b8af09455d1181256fd457bcbd6891 100644 (file)
@@ -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<Binary> 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<endian, maxalign, 64bit>
        if (ELF32LEObjectFile * object = dyn_cast<ELF32LEObjectFile>(op)) {